Skip to content

Commit 39ba04b

Browse files
committed
initial checkin
1 parent 086797e commit 39ba04b

File tree

77 files changed

+5868
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+5868
-1
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
target/
2+
bower_components/
3+
node_modules/
4+
dist/
5+
.idea/
6+
.tmp/
7+
.project
8+
.classpath
9+
.settings
10+
.metadata/
11+
*.iml
12+
*.log
13+
*.tmp
14+
*.zip
15+
*.bak
16+
17+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
18+
hs_err_pid*

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
# json-schema-validator
1+
# json-schema-validator
2+
A Java json schema validator that support json schema draft v4
3+
4+
* [Why to use this library?](#why-to-use-this-library)
5+
* [Maven installation](#maven-installation)
6+
* [Quickstart](#quickstart)
7+
8+
9+
This project is an implementation of the [JSON Schema Core Draft v4](http://json-schema.org/latest/json-schema-core.html)
10+
specification. It uses the [Jackson](https://github.com/FasterXML/jackson) for json parsing.
11+
12+
# Why to use this library?
13+
14+
* It is the fastest Java Json Schema Validator as far as I know. Here is the testing result compare with other two open
15+
source implementations. It is about 32 times faster than fge and 5 times faster than everit.
16+
17+
18+
fge: 7130ms
19+
20+
everit-org: 1168ms
21+
22+
networknt: 223ms
23+
24+
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)
25+
26+
* It uses jackson which is the most popular JSON parser in Java.
27+
28+
29+
30+
## Maven installation
31+
32+
Add the following to your `pom.xml`:
33+
34+
```xml
35+
<dependency>
36+
<groupId>com.networknt</groupId>
37+
<artifactId>json-schema-validator</artifactId>
38+
<version>0.1.0</version>
39+
</dependency>
40+
```
41+
42+
## Quickstart
43+
44+
45+
```
46+
JsonSchema schema = getJsonSchemaFromStringContent("{\"enum\":[1, 2, 3, 4],\"enumErrorCode\":\"Not in the list\"}");
47+
JsonNode node = getJsonNodeFromStringContent("7");
48+
Set<ValidationMessage> errors = schema.validate(node);
49+
assertThat(errors.size(), is(1));
50+
51+
```
52+

pom.xml

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.networknt</groupId>
5+
<artifactId>json-schema-validator</artifactId>
6+
<version>0.1.0</version>
7+
<description>A json schema validator that supports draft v4</description>
8+
<url>https://github.com/networknt/json-schema-validator</url>
9+
<name>JsonSchemaValidator</name>
10+
11+
<developers>
12+
<developer>
13+
<id>stevehu</id>
14+
<name>Steve Hu</name>
15+
<email>[email protected]</email>
16+
</developer>
17+
</developers>
18+
19+
<issueManagement>
20+
<system>github</system>
21+
<url>https://github.com/networknt/json-schema-validator/issues</url>
22+
</issueManagement>
23+
24+
<licenses>
25+
<license>
26+
<name>Apache License Version 2.0</name>
27+
<url>http://repository.jboss.org/licenses/apache-2.0.txt</url>
28+
<distribution>repo</distribution>
29+
</license>
30+
</licenses>
31+
32+
<scm>
33+
<connection>scm:git://github.com:networknt/json-schema-validator.git</connection>
34+
<developerConnection>scm:git://github.com:networknt/json-schema-validator.git</developerConnection>
35+
<url>https://github.com:networknt/json-schema-validator.git</url>
36+
</scm>
37+
38+
<distributionManagement>
39+
<snapshotRepository>
40+
<id>ossrh</id>
41+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
42+
</snapshotRepository>
43+
<repository>
44+
<id>ossrh</id>
45+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
46+
</repository>
47+
</distributionManagement>
48+
49+
<properties>
50+
<java.version>1.8</java.version>
51+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
52+
<version.jackson>2.8.2</version.jackson>
53+
<version.slf4j>1.7.21</version.slf4j>
54+
<version.common-lang>2.6</version.common-lang>
55+
<version.logback>1.1.7</version.logback>
56+
<version.junit>4.12</version.junit>
57+
<version.mockito>2.1.0-RC.1</version.mockito>
58+
<version.hamcrest>1.3</version.hamcrest>
59+
<version.undertow>1.4.0.Final</version.undertow>
60+
61+
</properties>
62+
63+
64+
<dependencies>
65+
<dependency>
66+
<groupId>com.fasterxml.jackson.core</groupId>
67+
<artifactId>jackson-databind</artifactId>
68+
<version>${version.jackson}</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.slf4j</groupId>
72+
<artifactId>slf4j-api</artifactId>
73+
<version>${version.slf4j}</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.slf4j</groupId>
77+
<artifactId>slf4j-ext</artifactId>
78+
<version>${version.slf4j}</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>commons-lang</groupId>
82+
<artifactId>commons-lang</artifactId>
83+
<version>${version.common-lang}</version>
84+
</dependency>
85+
86+
<dependency>
87+
<groupId>ch.qos.logback</groupId>
88+
<artifactId>logback-classic</artifactId>
89+
<version>${version.logback}</version>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>junit</groupId>
94+
<artifactId>junit</artifactId>
95+
<version>${version.junit}</version>
96+
<scope>test</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.mockito</groupId>
100+
<artifactId>mockito-core</artifactId>
101+
<version>${version.mockito}</version>
102+
<scope>test</scope>
103+
</dependency>
104+
<dependency>
105+
<groupId>org.hamcrest</groupId>
106+
<artifactId>hamcrest-all</artifactId>
107+
<version>${version.hamcrest}</version>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>io.undertow</groupId>
112+
<artifactId>undertow-core</artifactId>
113+
<version>${version.undertow}</version>
114+
</dependency>
115+
</dependencies>
116+
<build>
117+
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
118+
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
119+
<resources>
120+
<resource>
121+
<filtering>false</filtering>
122+
<directory>${basedir}/src/main/resources</directory>
123+
<includes>
124+
<include>**/*</include>
125+
</includes>
126+
</resource>
127+
</resources>
128+
<testResources>
129+
<testResource>
130+
<filtering>false</filtering>
131+
<directory>${basedir}/src/test/resources</directory>
132+
<includes>
133+
<include>**/*</include>
134+
</includes>
135+
</testResource>
136+
</testResources>
137+
138+
<plugins>
139+
<plugin>
140+
<groupId>org.sonatype.plugins</groupId>
141+
<artifactId>nexus-staging-maven-plugin</artifactId>
142+
<version>1.6.7</version>
143+
<extensions>true</extensions>
144+
<configuration>
145+
<serverId>ossrh</serverId>
146+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
147+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
148+
</configuration>
149+
</plugin>
150+
<!--
151+
<plugin>
152+
<groupId>org.apache.maven.plugins</groupId>
153+
<artifactId>maven-release-plugin</artifactId>
154+
<version>2.5.3</version>
155+
</plugin>
156+
-->
157+
158+
<plugin>
159+
<groupId>org.apache.maven.plugins</groupId>
160+
<artifactId>maven-source-plugin</artifactId>
161+
<version>3.0.1</version>
162+
<executions>
163+
<execution>
164+
<id>attach-sources</id>
165+
<goals>
166+
<goal>jar</goal>
167+
</goals>
168+
</execution>
169+
</executions>
170+
</plugin>
171+
<plugin>
172+
<groupId>org.apache.maven.plugins</groupId>
173+
<artifactId>maven-javadoc-plugin</artifactId>
174+
<version>2.10.4</version>
175+
<executions>
176+
<execution>
177+
<id>attach-javadocs</id>
178+
<goals>
179+
<goal>jar</goal>
180+
</goals>
181+
</execution>
182+
</executions>
183+
</plugin>
184+
<plugin>
185+
<groupId>org.apache.maven.plugins</groupId>
186+
<artifactId>maven-gpg-plugin</artifactId>
187+
<version>1.5</version>
188+
<executions>
189+
<execution>
190+
<id>sign-artifacts</id>
191+
<phase>verify</phase>
192+
<goals>
193+
<goal>sign</goal>
194+
</goals>
195+
</execution>
196+
</executions>
197+
</plugin>
198+
<plugin>
199+
<groupId>org.apache.maven.plugins</groupId>
200+
<artifactId>maven-compiler-plugin</artifactId>
201+
<version>2.5.1</version>
202+
<configuration>
203+
<source>${java.version}</source>
204+
<target>${java.version}</target>
205+
</configuration>
206+
</plugin>
207+
208+
<plugin>
209+
<groupId>org.apache.maven.plugins</groupId>
210+
<artifactId>maven-surefire-plugin</artifactId>
211+
<version>2.14</version>
212+
<dependencies>
213+
<dependency>
214+
<groupId>org.apache.maven.surefire</groupId>
215+
<artifactId>surefire-junit47</artifactId>
216+
<version>2.14</version>
217+
</dependency>
218+
</dependencies>
219+
</plugin>
220+
221+
222+
<!-- JACOCO added for code coverage -->
223+
<plugin>
224+
<groupId>org.jacoco</groupId>
225+
<artifactId>jacoco-maven-plugin</artifactId>
226+
<version>0.7.4.201502262128</version>
227+
<executions>
228+
<execution>
229+
<id>pre-unit-test</id>
230+
<goals>
231+
<goal>prepare-agent</goal>
232+
</goals>
233+
<configuration>
234+
<propertyName>surefireArgLine</propertyName>
235+
</configuration>
236+
</execution>
237+
<execution>
238+
<id>post-unit-test</id>
239+
<phase>test</phase>
240+
<goals>
241+
<goal>report</goal>
242+
</goals>
243+
</execution>
244+
</executions>
245+
</plugin>
246+
<!-- end JACOCO -->
247+
248+
</plugins>
249+
</build>
250+
251+
<reporting>
252+
<plugins>
253+
<plugin>
254+
<groupId>org.apache.maven.plugins</groupId>
255+
<artifactId>maven-surefire-report-plugin</artifactId>
256+
<version>2.19.1</version>
257+
</plugin>
258+
</plugins>
259+
</reporting>
260+
261+
</project>

0 commit comments

Comments
 (0)