diff --git a/src/main/java/com/networknt/schema/dialect/Dialect.java b/src/main/java/com/networknt/schema/dialect/Dialect.java index 6af636e91..52df32525 100644 --- a/src/main/java/com/networknt/schema/dialect/Dialect.java +++ b/src/main/java/com/networknt/schema/dialect/Dialect.java @@ -414,10 +414,10 @@ public String readDynamicAnchor(JsonNode schemaNode) { return null; } - private static String readText(JsonNode node, String field) { - JsonNode fieldNode = node.get(field); - return fieldNode == null ? null : fieldNode.asString(); - } + private static String readText(JsonNode node, String field) { + JsonNode fieldNode = node.get(field); + return fieldNode == null ? null : fieldNode.stringValue(null); + } public String getId() { return this.id; diff --git a/src/test/java/com/networknt/schema/Issue1246Test.java b/src/test/java/com/networknt/schema/Issue1246Test.java new file mode 100644 index 000000000..13615fa85 --- /dev/null +++ b/src/test/java/com/networknt/schema/Issue1246Test.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2026 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.networknt.schema; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class Issue1246Test { + @Test + void draft4SchemaIdResolutionIgnoresNonTextIdPropertySchemas() { + String schemaData = "{\n" + + " \"id\": \"https://www.example.org/schema#\",\n" + + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + + " \"type\": \"object\",\n" + + " \"properties\": {\n" + + " \"title\": {\n" + + " \"$ref\": \"http://json-schema.org/draft-04/schema#/properties/title\"\n" + + " }\n" + + " }\n" + + "}"; + Schema schema = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_4) + .getSchema(schemaData); + + assertTrue(schema.validate("{\"title\":\"Sample API\"}", InputFormat.JSON).isEmpty()); + } +}