Skip to content

fixes #1246 Coercion bug#1247

Merged
stevehu merged 2 commits into
masterfrom
issue1246
May 27, 2026
Merged

fixes #1246 Coercion bug#1247
stevehu merged 2 commits into
masterfrom
issue1246

Conversation

@stevehu

@stevehu stevehu commented May 26, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #1246 by preventing schema ID/anchor parsing from coercing non-string JSON nodes into text, which could incorrectly influence schema resource registration and $ref resolution (notably for Draft 4 where the ID keyword is id).

Changes:

  • Added a regression test covering Draft 4 schema resolution involving a $ref into the Draft 4 meta-schema.
  • Updated Dialect.readText(...) to return a value only when the target field exists and is a JSON string (no coercion).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/test/java/com/networknt/schema/Issue1246Test.java Adds regression coverage to ensure Draft 4 $ref resolution is not impacted by non-text nodes encountered under id-named fields.
src/main/java/com/networknt/schema/dialect/Dialect.java Tightens ID/anchor reading to ignore non-string values, avoiding unintended coercion effects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
private static String readText(JsonNode node, String field) {
JsonNode fieldNode = node.get(field);
return fieldNode != null && fieldNode.isString() ? fieldNode.asString() : null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the issue is that it shouldn't be coercing then these changes are confusing as asString() does coercing but isString() ensures it's a StringNode so the intent isn't clear.

More appropriate to use the following instead

    private static String readText(JsonNode node, String field) {
        JsonNode fieldNode = node.get(field);
        return fieldNode == null ? null : fieldNode.stringValue(null);
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I have made the code change based on your recommendation. Thanks a lot.

@stevehu stevehu merged commit 07b694b into master May 27, 2026
3 checks passed
@stevehu stevehu deleted the issue1246 branch May 27, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants