diff --git a/json-modules/json/pom.xml b/json-modules/json/pom.xml
index 04a00598a3..8a9f4f2c45 100644
--- a/json-modules/json/pom.xml
+++ b/json-modules/json/pom.xml
@@ -15,17 +15,11 @@
-
- org.everit.json
- org.everit.json.schema
- ${everit.json.schema.version}
-
-
- commons-logging
- commons-logging
-
-
-
+
+ com.networknt
+ json-schema-validator
+ ${networknt.json.schema.version}
+
org.json
json
@@ -72,7 +66,7 @@
- 1.4.1
+ 1.0.72
1.0
1.0.1
20211205
diff --git a/json-modules/json/src/test/java/com/baeldung/json/schema/JSONSchemaUnitTest.java b/json-modules/json/src/test/java/com/baeldung/json/schema/JSONSchemaUnitTest.java
index 393e052b95..491c320341 100644
--- a/json-modules/json/src/test/java/com/baeldung/json/schema/JSONSchemaUnitTest.java
+++ b/json-modules/json/src/test/java/com/baeldung/json/schema/JSONSchemaUnitTest.java
@@ -1,32 +1,44 @@
package com.baeldung.json.schema;
-import org.everit.json.schema.Schema;
-import org.everit.json.schema.ValidationException;
-import org.everit.json.schema.loader.SchemaLoader;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.util.Set;
-import org.json.JSONObject;
-import org.json.JSONTokener;
import org.junit.Test;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.networknt.schema.JsonSchema;
+import com.networknt.schema.JsonSchemaFactory;
+import com.networknt.schema.SpecVersion;
+import com.networknt.schema.ValidationMessage;
+
public class JSONSchemaUnitTest {
- @Test(expected = ValidationException.class)
- public void givenInvalidInput_whenValidating_thenInvalid() {
+ private ObjectMapper mapper = new ObjectMapper();
- JSONObject jsonSchema = new JSONObject(new JSONTokener(JSONSchemaUnitTest.class.getResourceAsStream("/schema.json")));
- JSONObject jsonSubject = new JSONObject(new JSONTokener(JSONSchemaUnitTest.class.getResourceAsStream("/product_invalid.json")));
+ @Test
+ public void givenInvalidInput_whenValidating_thenInvalid() throws IOException {
- Schema schema = SchemaLoader.load(jsonSchema);
- schema.validate(jsonSubject);
+ JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
+ JsonSchema jsonSchema = factory.getSchema(JSONSchemaUnitTest.class.getResourceAsStream("/schema.json"));
+
+ JsonNode jsonNode = mapper.readTree(JSONSchemaUnitTest.class.getResourceAsStream("/product_invalid.json"));
+ Set errors = jsonSchema.validate(jsonNode);
+ assertThat(errors).isNotEmpty()
+ .asString()
+ .contains("price: must have a minimum value of 0");
}
@Test
- public void givenValidInput_whenValidating_thenValid() {
+ public void givenValidInput_whenValidating_thenValid() throws IOException {
- JSONObject jsonSchema = new JSONObject(new JSONTokener(JSONSchemaUnitTest.class.getResourceAsStream("/schema.json")));
- JSONObject jsonSubject = new JSONObject(new JSONTokener(JSONSchemaUnitTest.class.getResourceAsStream("/product_valid.json")));
+ JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
+ JsonSchema jsonSchema = factory.getSchema(JSONSchemaUnitTest.class.getResourceAsStream("/schema.json"));
- Schema schema = SchemaLoader.load(jsonSchema);
- schema.validate(jsonSubject);
+ JsonNode jsonNode = mapper.readTree(JSONSchemaUnitTest.class.getResourceAsStream("/product_valid.json"));
+ Set errors = jsonSchema.validate(jsonNode);
+ assertThat(errors).isEmpty();
}
}