File tree 2 files changed +28
-0
lines changed
main/java/com/networknt/schema
test/java/com/networknt/schema
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ public static JsonType getSchemaNodeType(JsonNode node) {
75
75
* @return the json type
76
76
*/
77
77
public static JsonType getValueNodeType (JsonNode node , SchemaValidatorsConfig config ) {
78
+ if (node == null ) {
79
+ // This returns JsonType.UNKNOWN to be consistent with the behavior when
80
+ // JsonNodeType.MISSING
81
+ return JsonType .UNKNOWN ;
82
+ }
78
83
JsonNodeType type = node .getNodeType ();
79
84
switch (type ) {
80
85
case OBJECT :
Original file line number Diff line number Diff line change 2
2
3
3
import com .fasterxml .jackson .databind .JsonNode ;
4
4
import com .fasterxml .jackson .databind .ObjectMapper ;
5
+ import com .fasterxml .jackson .databind .node .MissingNode ;
5
6
import com .fasterxml .jackson .databind .node .ObjectNode ;
6
7
import com .networknt .schema .walk .JsonSchemaWalkListener ;
7
8
import com .networknt .schema .walk .WalkEvent ;
16
17
import java .util .Set ;
17
18
import java .util .TreeSet ;
18
19
20
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
19
21
import static org .junit .jupiter .api .Assertions .assertEquals ;
20
22
21
23
class JsonWalkTest {
@@ -110,6 +112,27 @@ void testWalkWithDifferentListeners() throws IOException {
110
112
+ "}" )));
111
113
}
112
114
115
+ @ Test
116
+ void testWalkMissingNodeWithPropertiesSchemaShouldNotThrow () {
117
+ String schemaContents = "{\n "
118
+ + " \" type\" : \" object\" ,\n "
119
+ + " \" properties\" : {\n "
120
+ + " \" field\" : {\n "
121
+ + " \" anyOf\" : [\n "
122
+ + " {\n "
123
+ + " \" type\" : \" string\" \n "
124
+ + " }\n "
125
+ + " ]\n "
126
+ + " }\n "
127
+ + " }\n "
128
+ + " }" ;
129
+
130
+ JsonSchemaFactory factory = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V7 );
131
+ JsonSchema schema = factory .getSchema (schemaContents );
132
+ JsonNode missingNode = MissingNode .getInstance ();
133
+ assertDoesNotThrow (() -> schema .walk (missingNode , true ));
134
+ }
135
+
113
136
private InputStream getSchema () {
114
137
return getClass ().getClassLoader ().getResourceAsStream ("schema/walk-schema.json" );
115
138
}
You can’t perform that action at this time.
0 commit comments