File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
main/java/com/networknt/schema
test/java/com/networknt/schema Expand file tree Collapse file tree 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) {
7575 * @return the json type
7676 */
7777 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+ }
7883 JsonNodeType type = node .getNodeType ();
7984 switch (type ) {
8085 case OBJECT :
Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .databind .JsonNode ;
44import com .fasterxml .jackson .databind .ObjectMapper ;
5+ import com .fasterxml .jackson .databind .node .MissingNode ;
56import com .fasterxml .jackson .databind .node .ObjectNode ;
67import com .networknt .schema .walk .JsonSchemaWalkListener ;
78import com .networknt .schema .walk .WalkEvent ;
1617import java .util .Set ;
1718import java .util .TreeSet ;
1819
20+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
1921import static org .junit .jupiter .api .Assertions .assertEquals ;
2022
2123class JsonWalkTest {
@@ -110,6 +112,27 @@ void testWalkWithDifferentListeners() throws IOException {
110112 + "}" )));
111113 }
112114
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+
113136 private InputStream getSchema () {
114137 return getClass ().getClassLoader ().getResourceAsStream ("schema/walk-schema.json" );
115138 }
You can’t perform that action at this time.
0 commit comments