Skip to content

Commit 07b694b

Browse files
authored
fixes #1246 Coercion bug (#1247)
* fixes #1246 Coercion bug * fixes #1247 refactor based on recommendation from justin
1 parent 9df7d32 commit 07b694b

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/main/java/com/networknt/schema/dialect/Dialect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ public String readDynamicAnchor(JsonNode schemaNode) {
414414
return null;
415415
}
416416

417-
private static String readText(JsonNode node, String field) {
418-
JsonNode fieldNode = node.get(field);
419-
return fieldNode == null ? null : fieldNode.asString();
420-
}
417+
private static String readText(JsonNode node, String field) {
418+
JsonNode fieldNode = node.get(field);
419+
return fieldNode == null ? null : fieldNode.stringValue(null);
420+
}
421421

422422
public String getId() {
423423
return this.id;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2026 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.networknt.schema;
17+
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
class Issue1246Test {
23+
@Test
24+
void draft4SchemaIdResolutionIgnoresNonTextIdPropertySchemas() {
25+
String schemaData = "{\n"
26+
+ " \"id\": \"https://www.example.org/schema#\",\n"
27+
+ " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n"
28+
+ " \"type\": \"object\",\n"
29+
+ " \"properties\": {\n"
30+
+ " \"title\": {\n"
31+
+ " \"$ref\": \"http://json-schema.org/draft-04/schema#/properties/title\"\n"
32+
+ " }\n"
33+
+ " }\n"
34+
+ "}";
35+
Schema schema = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_4)
36+
.getSchema(schemaData);
37+
38+
assertTrue(schema.validate("{\"title\":\"Sample API\"}", InputFormat.JSON).isEmpty());
39+
}
40+
}

0 commit comments

Comments
 (0)