You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix null enum members in validation error messages - #1374
Render explicit null enum members as null instead of an empty string in validation errors. Avoid appending a second null for nullable schemas that already enumerate it. Enum matching, including typeLoose coercion, retains its existing behavior.
Regression tests cover null at the beginning, middle and end of the enum, nullable enums with and without an explicit null, and valid null input. Existing heterogeneous enum message tests remain unchanged.
Validation: message regressions reproduced before the fix; full mvn -q test passed locally (10,573 tests, 0 failures, 0 errors, 30 skipped).
Scope: master/Jackson 3. The duplicate-null nullable message also exists on 2.x; its backport is deferred to a separate PR.
The input "" is already found by nodes.contains(JsonNodeValue.of("")) in validate(). isTypeLooseContainsInEnum is never reached, so this passes even if prepareLooseValue is reverted. That means "the empty string only matches when explicitly enumerated" is untested. A case that exercises the loose set would fix this. For example, check that "" does not match {"enum":[null,1]} or {"enum":[null]} (the second assertion above already covers the latter), and add a positive case that reaches the loose path.
Questions and minor points
Loose-mode behaviour change: with typeLoose, the string "null" now satisfies an enum that has a null member. The PR justifies this as restoring Jackson 2 behaviour, which seems plausible, but it is a user-visible semantic choice. The maintainers should confirm it, and the CHANGELOG entry could say so explicitly.
Duplicated literal: the text "null" is now spelled out in asString()'s result, in the nullable-append branch, and in prepareLooseValue. A small constant or helper would keep them in step.
Test style:com.networknt.schema.dialect.Dialects is referenced by its fully qualified name in nullableEnumListsNullOnce. An import would match the rest of the class.
CHANGELOG: the new entry has a blank line separating it from the other ### Changed bullets, and it uses a plain (#1373) where the entries right below use [#NNNN](url) links. The file mixes both styles, so this is cosmetic.
2.x: the duplicate-null message (nullable schema whose enum already lists null) also occurs on 2.x. Jackson 2's asText() rendered null as "null", and the nullable block then appends a second one. The !hasNull guard and its test may be worth backporting.
Re-reviewed at 1f692dd. This looks good to me, and CI is green on Java 17, 21 and 25.
The Dialects import and the CHANGELOG format are fixed.
The vacuous loose-mode assertion is gone along with the loose-mode change.
The core fix is unchanged and correct: null renders as null, and null is not listed twice for nullable schemas. The two new tests cover it.
Two follow-ups, neither blocking:
Loose mode on Jackson 3:prepareLooseValue still calls node.asString(), which returns "" for null. With typeLoose enabled, an enum containing null therefore matches the string "" rather than "null", which differs from Jackson 2. Dropping it from this PR is reasonable, but it would be worth tracking in a separate issue so it isn't lost.
2.x: the duplicate-null message (nullable schema whose enum already lists null) also occurs on 2.x, as noted in the PR.
Nit: the test class now ends with a blank line before the closing }.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1373.
Render explicit null enum members as
nullinstead of an empty string in validation errors. Avoid appending a second null for nullable schemas that already enumerate it. Enum matching, including typeLoose coercion, retains its existing behavior.Regression tests cover null at the beginning, middle and end of the enum, nullable enums with and without an explicit null, and valid null input. Existing heterogeneous enum message tests remain unchanged.
Validation: message regressions reproduced before the fix; full
mvn -q testpassed locally (10,573 tests, 0 failures, 0 errors, 30 skipped).Scope: master/Jackson 3. The duplicate-null nullable message also exists on 2.x; its backport is deferred to a separate PR.