Skip to content

Commit 21d80d2

Browse files
author
Matthias Sattel
committed
LIFEAPTE-5144 enable json-schema-validator to work with Android 5 and 6
1 parent 268413b commit 21d80d2

File tree

11 files changed

+48
-206
lines changed

11 files changed

+48
-206
lines changed

README.md

Lines changed: 1 addition & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1 @@
1-
[Stack Overflow](https://stackoverflow.com/questions/tagged/light-4j) |
2-
[Google Group](https://groups.google.com/forum/#!forum/light-4j) |
3-
[Gitter Chat](https://gitter.im/networknt/light-rest-4j) |
4-
[Subreddit](https://www.reddit.com/r/lightapi/) |
5-
[Youtube](https://www.youtube.com/channel/UCHCRMWJVXw8iB7zKxF55Byw) |
6-
[Documentation](https://doc.networknt.com/library/json-schema-validator/) |
7-
[Javadocs](https://www.javadoc.io/doc/com.networknt/json-schema-validator) |
8-
[Contribution Guide](https://doc.networknt.com/contribute/) |
9-
10-
[![Build Status](https://travis-ci.org/networknt/json-schema-validator.svg?branch=master)](https://travis-ci.org/networknt/json-schema-validator) [![codecov.io](https://codecov.io/github/networknt/json-schema-validator/coverage.svg?branch=master)](https://codecov.io/github/networknt/json-schema-validator?branch=master)
11-
12-
13-
This is a Java implementation of the [JSON Schema Core Draft v4-v7](http://json-schema.org/latest/json-schema-core.html) specification for JSON schema validation. In addition, it also works for OpenAPI 3.0 request/response validation with some [configuration flags](doc/config.md). The default JSON parser is the [Jackson](https://github.com/FasterXML/jackson) that is the most popular one. As it is a key component in our [light-4j](https://github.com/networknt/light-4j) microservices framework to validate request/response against OpenAPI specification for [light-rest-4j](http://www.networknt.com/style/light-rest-4j/) and RPC schema for [light-hybrid-4j](http://www.networknt.com/style/light-hybrid-4j/) at runtime, performance is the most important aspect in the design.
14-
15-
## Why this library
16-
17-
#### Performance
18-
19-
It is the fastest Java JSON Schema Validator as far as I know. Here is the testing result compare with the other two open-source implementations. It is about 32 times faster than the Fge and five times faster than the Everit.
20-
21-
fge: 7130ms
22-
23-
everit-org: 1168ms
24-
25-
networknt: 223ms
26-
27-
You can run the performance tests for three libraries from [https://github.com/networknt/json-schema-validator-perftest](https://github.com/networknt/json-schema-validator-perftest)
28-
29-
#### Parser
30-
31-
It uses Jackson that is the most popular JSON parser in Java. If you are using Jackson parser already in your project, it is natural to choose this library over others for schema validation.
32-
33-
#### Dependency
34-
35-
Following the design principle of the Light Platform, this library has minimum dependencies to ensure there are no dependency conflicts when using it.
36-
37-
Here are the dependencies.
38-
39-
```
40-
<dependency>
41-
<groupId>com.fasterxml.jackson.core</groupId>
42-
<artifactId>jackson-databind</artifactId>
43-
<version>${version.jackson}</version>
44-
</dependency>
45-
<dependency>
46-
<groupId>org.slf4j</groupId>
47-
<artifactId>slf4j-api</artifactId>
48-
<version>${version.slf4j}</version>
49-
</dependency>
50-
<dependency>
51-
<groupId>org.apache.commons</groupId>
52-
<artifactId>commons-lang3</artifactId>
53-
<version>${version.common-lang3}</version>
54-
</dependency>
55-
```
56-
57-
#### Community
58-
59-
This library is very active with a lot of contributors. New features and bug fixes are handled quickly by the team members. Because it is an essential dependency of the [light-4j](https://github.com/networknt/light-4j) framework in the same GitHub organization, it will be evolved and maintained along with the framework.
60-
61-
## Prerequisite
62-
63-
The library supports Java 8 and up. If you want to build from the source code, you need to install JDK 8 locally. To support multiple version of JDK, you can use [SDKMAN](https://www.networknt.com/tool/sdk/)
64-
65-
## Dependency
66-
67-
This package is available on Maven central.
68-
69-
Maven:
70-
71-
```xml
72-
<dependency>
73-
<groupId>com.networknt</groupId>
74-
<artifactId>json-schema-validator</artifactId>
75-
<version>1.0.27</version>
76-
</dependency>
77-
```
78-
79-
Gradle:
80-
81-
```
82-
dependencies {
83-
compile(group: "com.networknt", name: "json-schema-validator", version: "1.0.27");
84-
}
85-
```
86-
87-
For the latest version, please check the [release](https://github.com/networknt/json-schema-validator/releases) page.
88-
89-
## [Quick Start](doc/quickstart.md)
90-
91-
## [Validators](doc/validators.md)
92-
93-
## [Configuration](doc/config.md)
94-
95-
## [Specification Version](doc/specversion.md)
96-
97-
## [YAML Validation](doc/yaml.md)
98-
99-
## Known issues
100-
101-
I have just updated the test suites from the [official website](https://github.com/json-schema-org/JSON-Schema-Test-Suite) as the old ones were copied from another Java validator. Now there are several issues that need to be addressed. All of them are edge cases, in my opinion, but need to be investigated. As my old test suites were inherited from another Java JSON Schema Validator, I guess other Java Validator would have the same issues as these issues are in the Java language itself.
102-
103-
[#7](https://github.com/networknt/json-schema-validator/issues/7)
104-
105-
[#5](https://github.com/networknt/json-schema-validator/issues/5)
106-
107-
## Contributors
108-
109-
Thanks to the following people who have contributed to this project. If you are using this library, please consider to be a sponsor for one of the contributors.
110-
111-
[@stevehu](https://github.com/sponsors/stevehu)
112-
113-
[@jiachen1120](https://github.com/jiachen1120)
114-
115-
[@BalloonWen](https://github.com/BalloonWen)
116-
117-
[@eskabetxe](https://github.com/eskabetxe)
118-
119-
[@ddobrin](https://github.com/ddobrin)
120-
121-
[@ehrmann](https://github.com/ehrmann)
122-
123-
[@rhwood](https://github.com/rhwood)
124-
125-
[@nitin1891](https://github.com/nitin1891)
126-
127-
[@jawaff](https://github.com/jawaff)
128-
129-
[@kosty](https://github.com/kosty)
130-
131-
[@chenyan71](https://github.com/chenyan71)
132-
133-
[@chrisken](https://github.com/chrisken)
134-
135-
[@NicholasAzar](https://github.com/NicholasAzar)
136-
137-
[@basinilya](https://github.com/basinilya)
138-
139-
For all contributors, please visit https://github.com/networknt/json-schema-validator/graphs/contributors
140-
141-
If you are a contributor, please join the [GitHub Sponsors](https://github.com/sponsors) and swithch the link to your sponsors dashboard via a PR.
142-
143-
## Sponsors
144-
145-
146-
### Individual Sponsors
147-
148-
149-
### Corporation Sponsors
150-
151-
152-
1+
## This is a fork of https://github.com/networknt/json-schema-validator to support Android 6 API >=23

pom.xml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<modelVersion>4.0.0</modelVersion>
2020
<groupId>com.networknt</groupId>
2121
<artifactId>json-schema-validator</artifactId>
22-
<version>1.0.27</version>
22+
<version>1.0.27-CGM</version>
2323
<packaging>bundle</packaging>
2424
<description>A json schema validator that supports draft v4</description>
2525
<url>https://github.com/networknt/json-schema-validator</url>
@@ -48,17 +48,13 @@
4848
<url>https://github.com:networknt/json-schema-validator.git</url>
4949
</scm>
5050
<distributionManagement>
51-
<snapshotRepository>
52-
<id>ossrh</id>
53-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
54-
</snapshotRepository>
5551
<repository>
56-
<id>ossrh</id>
57-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
52+
<id>life.release</id>
53+
<url>https://artifactory.cgm.ag/cgm.life.partner.release/</url>
5854
</repository>
5955
</distributionManagement>
6056
<properties>
61-
<java.version>1.8</java.version>
57+
<java.version>1.6</java.version>
6258
<java.testversion>1.8</java.testversion>
6359
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6460
<version.jackson>2.10.0</version.jackson>
@@ -145,17 +141,6 @@
145141
<version>4.2.1</version>
146142
<extensions>true</extensions>
147143
</plugin>
148-
<plugin>
149-
<groupId>org.sonatype.plugins</groupId>
150-
<artifactId>nexus-staging-maven-plugin</artifactId>
151-
<version>1.6.8</version>
152-
<extensions>true</extensions>
153-
<configuration>
154-
<serverId>ossrh</serverId>
155-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
156-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
157-
</configuration>
158-
</plugin>
159144
<!--
160145
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-release-plugin</artifactId><version>2.5.3</version></plugin>
161146
-->
@@ -192,6 +177,8 @@
192177
<configuration>
193178
<source>${java.version}</source>
194179
<target>${java.version}</target>
180+
<testSource>${java.testversion}</testSource>
181+
<testTarget>${java.testversion}</testTarget>
195182
</configuration>
196183
<executions>
197184
<execution>
@@ -291,7 +278,7 @@
291278
<plugin>
292279
<groupId>org.jacoco</groupId>
293280
<artifactId>jacoco-maven-plugin</artifactId>
294-
<version>${version.jacoco}</version>
281+
<version>0.7.9</version>
295282
<executions>
296283
<!-- The Executions for merging -->
297284
<execution>

src/main/java/com/networknt/schema/ExclusiveMinimumValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ExclusiveMinimumValidator extends BaseJsonValidator implements Json
3434
*/
3535
private final ThresholdMixin typedMinimum;
3636

37-
public ExclusiveMinimumValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
37+
public ExclusiveMinimumValidator(String schemaPath, final JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
3838
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.EXCLUSIVE_MINIMUM, validationContext);
3939

4040
if (!schemaNode.isNumber()) {

src/main/java/com/networknt/schema/JsonMetaSchema.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static class V4 {
6969
private static String URI = "http://json-schema.org/draft-04/schema#";
7070
private static final String ID = "id";
7171

72-
public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
72+
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
7373
static {
7474
// add version specific formats here.
7575
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
@@ -98,7 +98,7 @@ private static class V6 {
9898
// Draft 6 uses "$id"
9999
private static final String ID = "$id";
100100

101-
public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
101+
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
102102
static {
103103
// add version specific formats here.
104104
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
@@ -126,7 +126,7 @@ private static class V7 {
126126
private static String URI = "http://json-schema.org/draft-07/schema#";
127127
private static final String ID = "$id";
128128

129-
public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
129+
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
130130
static {
131131
// add version specific formats here.
132132
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
@@ -154,7 +154,7 @@ private static class V201909 {
154154
private static String URI = "http://json-schema.org/draft/2019-09/schema#";
155155
private static final String ID = "$id";
156156

157-
public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
157+
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
158158
static {
159159
// add version specific formats here.
160160
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));

src/main/java/com/networknt/schema/JsonSchemaFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co
313313

314314
final URI mappedUri;
315315
try {
316-
mappedUri = this.uriFactory.create(map.getOrDefault(schemaUri.toString(), schemaUri.toString()));
316+
mappedUri = this.uriFactory.create(map.get(schemaUri.toString())!=null ? map.get(schemaUri.toString()) : schemaUri.toString());
317317
} catch (IllegalArgumentException e) {
318318
logger.error("Failed to create URI.", e);
319319
throw new JsonSchemaException(e);

src/main/java/com/networknt/schema/MinimumValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class MinimumValidator extends BaseJsonValidator implements JsonValidator
3737
*/
3838
private final ThresholdMixin typedMinimum;
3939

40-
public MinimumValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
40+
public MinimumValidator(String schemaPath, final JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
4141
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.MINIMUM, validationContext);
4242

4343
if (!schemaNode.isNumber()) {

src/main/java/com/networknt/schema/ValidationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ValidationContext {
2727
private final JsonMetaSchema metaSchema;
2828
private final JsonSchemaFactory jsonSchemaFactory;
2929
private SchemaValidatorsConfig config;
30-
private final Map<String, JsonSchemaRef> refParsingInProgress = new HashMap<>();
30+
private final Map<String, JsonSchemaRef> refParsingInProgress = new HashMap<String, JsonSchemaRef>();
3131

3232
public ValidationContext(URIFactory uriFactory, JsonMetaSchema metaSchema, JsonSchemaFactory jsonSchemaFactory, SchemaValidatorsConfig config) {
3333
if (uriFactory == null) {

src/main/java/com/networknt/schema/uri/ClasspathURLFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public URI create(final String uri)
4545
{
4646
try {
4747
return new URL(null, uri, STREAM_HANDLER).toURI();
48-
} catch (MalformedURLException | URISyntaxException e) {
48+
} catch (MalformedURLException e) {
49+
throw new IllegalArgumentException("Unable to create URI.", e);
50+
} catch (URISyntaxException e) {
4951
throw new IllegalArgumentException("Unable to create URI.", e);
5052
}
5153
}
@@ -58,7 +60,9 @@ public URI create(final URI baseURI, final String segment)
5860
{
5961
try {
6062
return new URL(convert(baseURI), segment, STREAM_HANDLER).toURI();
61-
} catch (MalformedURLException | URISyntaxException e) {
63+
} catch (MalformedURLException e) {
64+
throw new IllegalArgumentException("Unable to create URI.", e);
65+
} catch (URISyntaxException e) {
6266
throw new IllegalArgumentException("Unable to create URI.", e);
6367
}
6468
}

src/main/java/com/networknt/schema/uri/ClasspathURLStreamHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author <a href="mailto:[email protected]">Kenneth Waldenstrom</a>
3333
*/
3434
class ClasspathURLStreamHandler extends URLStreamHandler {
35-
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<>(
35+
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<String>(
3636
Arrays.asList("classpath", "resource")));
3737

3838
@Override

src/main/java/com/networknt/schema/uri/URLFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public final class URLFactory implements URIFactory {
3232
// These supported schemes are defined in {@link #URL(String, String, int, String)}.
33-
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<>(
33+
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<String>(
3434
Arrays.asList("http", "https", "ftp", "file", "jar")));
3535

3636
/**
@@ -42,7 +42,9 @@ public URI create(final String uri)
4242
{
4343
try {
4444
return new URL(uri).toURI();
45-
} catch (MalformedURLException | URISyntaxException e) {
45+
} catch (MalformedURLException e) {
46+
throw new IllegalArgumentException("Unable to create URI.", e);
47+
} catch (URISyntaxException e) {
4648
throw new IllegalArgumentException("Unable to create URI.", e);
4749
}
4850
}
@@ -57,7 +59,9 @@ public URI create(final URI baseURI, final String segment)
5759
{
5860
try {
5961
return new URL(baseURI.toURL(), segment).toURI();
60-
} catch (MalformedURLException | URISyntaxException e) {
62+
} catch (MalformedURLException e) {
63+
throw new IllegalArgumentException("Unable to create URI.", e);
64+
} catch (URISyntaxException e) {
6165
throw new IllegalArgumentException("Unable to create URI.", e);
6266
}
6367
}

0 commit comments

Comments
 (0)