Skip to content

Commit a31eaf7

Browse files
committed
Add JSON Schema validation
1 parent ef7ec7e commit a31eaf7

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.baeldung.json.schema;
22

33
import org.everit.json.schema.Schema;
4-
import org.everit.json.schema.ValidationException;
54
import org.everit.json.schema.loader.SchemaLoader;
65

76
import org.json.JSONObject;
@@ -17,17 +16,7 @@ public void givenInvalidInput_whenValidating_thenInvalid() {
1716
JSONObject jsonSubject = new JSONObject(new JSONTokener(JSONSchemaTest.class.getResourceAsStream("/product_invalid.json")));
1817

1918
Schema schema = SchemaLoader.load(jsonSchema);
20-
21-
try {
22-
23-
schema.validate(jsonSubject);
24-
}
25-
26-
catch (ValidationException e) {
27-
28-
System.out.println(e.getMessage());
29-
e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(System.out::println);
30-
}
19+
schema.validate(jsonSubject);
3120
}
3221

3322
@Test
@@ -37,16 +26,6 @@ public void givenValidInput_whenValidating_thenValid() {
3726
JSONObject jsonSubject = new JSONObject(new JSONTokener(JSONSchemaTest.class.getResourceAsStream("/product_valid.json")));
3827

3928
Schema schema = SchemaLoader.load(jsonSchema);
40-
41-
try {
42-
43-
schema.validate(jsonSubject);
44-
}
45-
46-
catch (ValidationException e) {
47-
48-
System.out.println(e.getMessage());
49-
e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(System.out::println);
50-
}
29+
schema.validate(jsonSubject);
5130
}
5231
}

0 commit comments

Comments
 (0)