File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
src/test/java/com/networknt/schema Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .networknt .schema ;
2
+
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
4
+ import com .fasterxml .jackson .databind .JsonNode ;
5
+ import com .fasterxml .jackson .databind .ObjectMapper ;
6
+ import org .junit .Test ;
7
+
8
+ import java .util .Set ;
9
+
10
+ public class UnknownMetaSchemaTest {
11
+
12
+ private String schema =
13
+ "{\n " +
14
+ " \" $schema\" : \" https://json-schema.org/draft-07/schema\" ,\n " +
15
+ " \" title\" : \" thingModel\" ,\n " +
16
+ " \" description\" : \" description of thing\" ,\n " +
17
+ " \" type\" : \" object\" ,\n " +
18
+ " \" properties\" : {\n " +
19
+ " \" data\" : {\n " +
20
+ " \" type\" : \" integer\" \n " +
21
+ " }\n " +
22
+ " },\n " +
23
+ " \" required\" : [\n " +
24
+ " \" data\" \n " +
25
+ " ]\n " +
26
+ "}" ;
27
+
28
+ private String json =
29
+ "{\n " +
30
+ " \" data\" : 1\n " +
31
+ "}" ;
32
+
33
+
34
+ @ Test
35
+ public void test () throws JsonProcessingException {
36
+ ObjectMapper mapper = new ObjectMapper ();
37
+ JsonNode jsonNode = mapper .readTree (this .json );
38
+
39
+ JsonSchemaFactory factory = JsonSchemaFactory .builder (JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V7 )).objectMapper (mapper ).build ();
40
+ JsonSchema jsonSchema = factory .getSchema (schema );
41
+
42
+ Set <ValidationMessage > errors = jsonSchema .validate (jsonNode );
43
+ for (ValidationMessage error :errors ) {
44
+ System .out .println (error .getMessage ());
45
+ }
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments