Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This project does not adhere to [Semantic Versioning](https://semver.org/) and m
- Opt-in `ExecutionConfig.maxEvaluationSteps` and `maxEvaluationDepth` limits for validation and schema walking, including walking without assertions. Exhaustion throws `ValidationLimitExceededException` instead of returning a partial validity result. Both limits default to unlimited; they bound admitted evaluation steps and schema frames, not work inside a keyword. (#1276)

### Changed
- Share numeric value equality across `const`, `enum` and `uniqueItems`, including numbers nested in arrays and objects. Numeric hashing handles extreme decimal scales without overflowing during trailing-zero normalization; non-finite float and double nodes compare consistently. Preserve `enum` conversion hooks and its existing `typeLoose` text representation (Jackson 3 normalized decimal text, e.g. `100` matches `"1E+2"`); skip container members during loose string matching and prepare scalar text once. (#1307)
- With `typeLoose` enabled, numeric `enum` members now match strings by exact decimal value on both master and 2.x: `enum: [100]` accepts `"100"`, `"100.0"` and `"1E+2"`. Previously master required normalized exponent text while 2.x used plain decimal text. This intentionally broadens accepted numeric spellings. Inputs must follow JSON number syntax; whitespace, leading `+`, leading integer zeros and numeric separators are rejected. Signed zero and equivalent trailing-zero/exponent forms compare equally. Exponents are scanned with bounded arithmetic without expanding zeros or constructing a large exponent integer. Strict mode, literal string members, container handling, non-finite member text and protected enum conversion hooks retain their existing behavior. The comparison uses the enum node's existing decimal value; precision already lost by schema parsing is not recovered. (#1349)
- Share numeric value equality across `const`, `enum` and `uniqueItems`, including numbers nested in arrays and objects. Numeric hashing handles extreme decimal scales without overflowing during trailing-zero normalization; non-finite float and double nodes compare consistently. Preserve `enum` conversion hooks; skip container members during loose string matching and prepare scalar matching values once. (#1307)
- Preserve count and length limits beyond the `int` range for `minItems`, `maxItems`, `minProperties`, `maxProperties`, `minLength`, `maxLength`, `minContains`, and `maxContains`. Count-limit error arguments are ungrouped Strings; plain integer limits keep their full decimal spelling, while exponent-form decimals remain bounded in size. Contains annotations use the parsed node's own numeric value and type without int-range coercion. Accepted YAML numeric separators retain their meaning. (#1334, #1346)
- Built-in readers apply the same selective decimal parsing to schemas and instances: lossy floats under the eight count names become DecimalNodes, including fields inside literal data, defaults and examples. `getSchemaNode()`, applied defaults and annotations expose those exact nodes. Copies and moved/rebuilt nodes keep precision without a global side table. Losslessness compares written decimals with the double's shortest decimal representation; unrelated numbers and ordinary values such as `0.1` remain unchanged. A JsonNode from an external plain mapper cannot recover lost digits and can differ from an exact `const`/`enum` literal; custom readers/factories retain their numeric policies. DecimalNode scale and serialization can differ between Jackson 2 and 3. Integral floating/decimal count messages use plain digits up to 100 integer digits (precision minus scale), with scientific notation beyond that to bound zero expansion; integer nodes retain full decimal spelling. Tokens outside BigDecimal's parsing range retain ordinary parsing, including Infinity saturation for huge positive exponents and zero underflow for huge negative exponents. (#1350)
- Without Ethlo on the classpath, the `date-time` format now checks the date with the rules of the `date` format and the time with the rules of the `time` format instead of `OffsetDateTime.parse(..)`. It rejects a time without seconds (`2020-01-01T12:00Z`), an offset without minutes (`+01`) and an empty fraction (`12:00:00.Z`), which Ethlo already rejected, as well as an offset with seconds (`+01:00:00`). It accepts an offset up to `23:59` and a fraction longer than nine digits, which RFC 3339 allows, and a leap second at the end of a June 30 or a December 31 in UTC, which it used to reject. Compared with Ethlo, the fallback provides less accurate leap-second validation because it does not check that a leap second was actually inserted on that date. It also accepts `-00:00`, offsets beyond ±18:00, and fractions longer than nine digits, which Ethlo rejects. The fallback requires `T` or `t` between the date and time, rejecting a space separator such as `2020-01-01 12:00:00Z` that Ethlo accepts. (#1316, #1337)
Expand Down
16 changes: 15 additions & 1 deletion doc/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@ When the format assertion vocabularies are used in a meta schema, in accordance

##### Footnotes
1. Note that the validation are only optional for some of the keywords/formats.
2. Refer to the corresponding JSON schema for more information on whether the keyword/format is optional or not.
2. Refer to the corresponding JSON schema for more information on whether the keyword/format is optional or not.

## Loose numeric enum strings

With `SchemaRegistryConfig.typeLoose(true)`, finite numeric enum members match string instances by exact decimal value. For `{"enum":[100]}`, `"100"`, `"100.0"`, `"1e2"` and `"1E+2"` all match on both branches. With loose typing disabled, these strings do not match numeric `100`.

This deliberately broadens the old behavior: master formerly used normalized decimal text (for example `"1E+2"`), while 2.x used plain text (`"100"`). Applications relying on rejection of equivalent spellings should disable loose typing or constrain the allowed strings explicitly.

Strings must follow JSON number syntax: optional minus, an integer without leading zeros, an optional fraction with digits after the decimal point, and an optional exponent with digits. Whitespace, a leading plus, hexadecimal forms, underscores and incomplete fractions/exponents do not match a numeric member. Exponent signs and leading exponent zeros are allowed. Positive and negative zero compare equally, including zero with arbitrarily long exponents. Nonzero exponents outside any representable enum value simply do not match; parsing never expands exponent-form numbers or constructs an arbitrarily large exponent integer.

Only top-level numeric enum members receive this conversion. A literal string member such as `"1E+2"` remains an exact string, and arrays/objects are not coerced from strings or traversed for loose numeric coercion. Existing scalar matching for booleans, null and explicitly supplied non-finite numbers is retained; non-finite numeric members keep their existing exact text spellings rather than accepting huge finite exponent strings.

The comparison uses each numeric enum node's existing decimal value, consistent with numeric value equality. It does not recover digits already rounded by a caller's mapper or the configured schema reader. Protected enum conversion hooks remain in use.

For example, a default reader rounds `{"enum":[9007199254740993.0]}` to a double-valued member. Loose matching therefore accepts `"9007199254740992"`, not `"9007199254740993"`. Configure the schema reader's mapper with `USE_BIG_DECIMAL_FOR_FLOATS`, or supply an exact DecimalNode, to preserve the written value; then those verdicts reverse. This enum change does not alter schema-reader precision policy.
46 changes: 46 additions & 0 deletions doc/issue-1349-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Issue #1349 validation: master

Issue: https://github.com/networknt/json-schema-validator/issues/1349

Local verification performed on 2026-10-23 against base `947702f`. The user selected exact numeric-value matching for loose numeric enum strings on both branches.

## Changes

- Numeric enum 100 accepts strings 100, 100.0, 1e2 and 1E+2 in typeLoose mode. Strict mode and literal string enum members retain their semantics.
- NumericStringValue is a package-private immutable key storing sign, significant coefficient digits and a long decimal power. JSON number text is scanned linearly, with a saturating long exponent; no arbitrary-size exponent BigInteger or expanded zero suffix is created. Saturation is beyond any BigDecimal coefficient/scale combination. Zero still requires a complete valid grammar before its exponent is ignored.
- Keys are prepared once per distinct converted enum value. Each string is parsed at most once for numeric lookup, with separate exact scalar-text matching. Strict mode reuses empty sets.
- Existing protected numeric/array conversion hooks remain in use; containers are not coerced from strings. Non-finite members preserve their previous exact text spellings and do not match huge finite exponent strings.
- The numeric key uses the node's existing decimalValue(); precision already lost by schema parsing is not recovered. JsonNodeValue equality/hashing are untouched.
- Changelog and doc/compatibility.md describe the intentional expansion in accepted spellings on both branches, JSON number grammar, signed zero, finite/nonfinite boundaries and migration guidance.

## Verification

Command: `mvn -B clean verify`, selecting each JDK with `JAVA_HOME` and `PATH`.


| Branch | JDK | Unit cases | Existing skips | Artifact checks | Result |
| --- | --- | ---: | ---: | ---: | --- |
| master | 17.0.13-amzn | 10451 | 30 | 1 | PASS |
| master | 21.0.5-amzn | 10451 | 30 | 1 | PASS |
| master | 25.0.3-amzn | 10451 | 30 | 1 | PASS |

- Master: 10,451 cases plus one artifact check on JDK 17/21/25; 30 existing skips.
- Issue1349Test covers all five supported dialects; accepted equivalent forms; malformed/whitespace/Unicode/leading-zero text; strict and literal-string behavior; containers, boolean text and equivalent members; exact integers above 2^53; signed zero; all finite Jackson numeric node types; explicit NaN/Infinity member spellings; BigDecimal minimum/maximum scales; 100,000-digit exponents; and long fractional mantissas.
- NumericStringValueTest checks one million pairs against BigDecimal comparison, 1,000 rescaled/engineering spellings with hash agreement, and 20,000 generated strings against an independent JSON-number regex.
- Updated pre-existing branch-specific loose enum tests to assert the selected numeric-value policy. All existing numeric equality and protected conversion-hook tests remain active.

## Limits

- These are local results; remote CI is a separate acceptance gate.
- GitNexus reported LOW as a lower-bound estimate for EnumValidator, with zero direct indexed callers/processes and warnings that interface dispatch is untraced. It cannot scan the two unindexed worktrees, so it does not qualify the final diff. Source review, regression tests, complete JDK matrices and git diff --check provide local evidence.
- No performance claims or reader-policy changes are included. Numeric coercion is limited to finite top-level enum members, plus the separately retained non-finite exact-text behavior.

## Review follow-up

The new regression test reproduced the 2.x BinaryNode null-text exception before the fix. `NumericStringValue.parse(null)` now returns no numeric match. BinaryNode and POJONode instances classified as strings produce normal validation errors when they expose no matching numeric text. The parser-level null contract is tested on both branches.

Additional tests demonstrate the schema-reader boundary: the default reader rounds `9007199254740993.0` and matches `"9007199254740992"`; an explicit `USE_BIG_DECIMAL_FOR_FLOATS` reader preserves the written value and matches `"9007199254740993"`. This is documented behavior, not a change to reader precision policy.

The two linear passes in the parser are retained: one validates the complete grammar and scans the exponent, and the other identifies significant coefficient digits. This keeps validation separate from normalization and does not expand exponents. No new performance claim is made.

All JDK rows above were rerun after this follow-up. The preceding PR head was `6aeb391`. GitNexus could not locate the new NumericStringValue helper (UNKNOWN), so source/call-site review and the complete test matrices provide verification for this change.
27 changes: 11 additions & 16 deletions src/main/java/com/networknt/schema/keyword/EnumValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
import com.networknt.schema.utils.TypeFactory;
import com.networknt.schema.SchemaContext;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -41,7 +37,8 @@
public class EnumValidator extends BaseKeywordValidator implements KeywordValidator {
private final Set<JsonNodeValue> nodes;
private final String error;
private final List<Predicate<String>> looseValues = new ArrayList<>();
private final Set<String> looseValues;
private final Set<NumericStringValue> looseNumbers;

static String asString(JsonNode node) {
if (node.isObject() || node.isArray() || node.isString()) {
Expand All @@ -53,6 +50,9 @@ static String asString(JsonNode node) {

public EnumValidator(SchemaLocation schemaLocation, JsonNode schemaNode, Schema parentSchema, SchemaContext schemaContext) {
super(KeywordType.ENUM, schemaNode, schemaLocation, parentSchema, schemaContext);
boolean typeLoose = schemaContext.getSchemaRegistryConfig().isTypeLoose();
looseValues = typeLoose ? new HashSet<>() : Collections.emptySet();
looseNumbers = typeLoose ? new HashSet<>() : Collections.emptySet();
if (schemaNode != null && schemaNode.isArray()) {
nodes = new HashSet<>();
StringBuilder sb = new StringBuilder();
Expand All @@ -68,7 +68,7 @@ public EnumValidator(SchemaLocation schemaLocation, JsonNode schemaNode, Schema
converted = processArrayNode((ArrayNode) n);
}
boolean added = nodes.add(JsonNodeValue.of(converted));
if (added && schemaContext.getSchemaRegistryConfig().isTypeLoose()) {
if (added && typeLoose) {
prepareLooseValue(converted);
}

Expand Down Expand Up @@ -120,11 +120,10 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
private boolean isTypeLooseContainsInEnum(JsonNode node) {
if (TypeFactory.getValueNodeType(node, this.schemaContext.getSchemaRegistryConfig()) == JsonType.STRING) {
String nodeText = node.asString();
for (Predicate<String> value : looseValues) {
if (value.test(nodeText)) {
return true;
}
if (looseValues.contains(nodeText)) {
return true;
}
return !looseNumbers.isEmpty() && looseNumbers.contains(NumericStringValue.parse(nodeText));
}
return false;
}
Expand All @@ -135,13 +134,9 @@ private void prepareLooseValue(JsonNode node) {
return;
}
if (node.isNumber() && !JsonNodeTypes.isNonFiniteNumber(node)) {
BigDecimal decimal = node.decimalValue();
// Preserve Jackson 3's historical normalized decimal text (100 -> 1E+2).
String text = JsonNodeValue.normalize(decimal).toString();
looseValues.add(text::equals);
looseNumbers.add(NumericStringValue.of(node.decimalValue()));
} else {
String text = node.asString();
looseValues.add(text::equals);
looseValues.add(node.asString());
}
}

Expand Down
Loading
Loading