Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
for k in totals: totals[k]+=int(r.get(k,'0'))
except Exception:
pass
exp_tests=460
exp_tests=464
exp_skipped=0
if totals['tests']!=exp_tests or totals['skipped']!=exp_skipped:
print(f"Unexpected test totals: {totals} != expected tests={exp_tests}, skipped={exp_skipped}")
Expand Down
8 changes: 8 additions & 0 deletions json-java21-jtd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ Validates primitive types:

Supported types: `boolean`, `string`, `timestamp`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `float32`, `float64`

#### Integer Type Validation
Integer types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`) validate based on **numeric value**, not textual representation:

- **Valid integers**: `3`, `3.0`, `3.000`, `42.00` (mathematically integers)
- **Invalid integers**: `3.1`, `3.14`, `3.0001` (have fractional components)

This follows RFC 8927 §2.2.3.1: "An integer value is a number without a fractional component."

### 4. Enum Schema
Validates against string values:
```json
Expand Down
4 changes: 2 additions & 2 deletions json-java21-jtd/src/main/java/json/java21/jtd/Jtd.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ JtdSchema compilePropertiesSchema(JsonObject obj) {
}
additionalProperties = bool.value();
} else if (properties.isEmpty() && optionalProperties.isEmpty()) {
// Empty schema with no properties defined allows additional properties by default
additionalProperties = true;
// Empty schema with no properties defined rejects additional properties by default
additionalProperties = false;
}

return new JtdSchema.PropertiesSchema(properties, optionalProperties, additionalProperties);
Expand Down
7 changes: 7 additions & 0 deletions json-java21-jtd/src/main/java/json/java21/jtd/JtdSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ Jtd.Result validateInteger(JsonValue instance, String type, boolean verboseError
return Jtd.Result.failure(Jtd.Error.EXPECTED_INTEGER.message());
}

// Handle BigDecimal - check if it has fractional component (not just scale > 0)
// RFC 8927 §2.2.3.1: "An integer value is a number without a fractional component"
// Values like 3.0 or 3.000 are valid integers despite positive scale, but 3.1 is not
if (value instanceof java.math.BigDecimal bd && bd.remainder(java.math.BigDecimal.ONE).signum() != 0) {
return Jtd.Result.failure(Jtd.Error.EXPECTED_INTEGER.message());
}

// Convert to long for range checking
long longValue = value.longValue();

Expand Down
Loading
Loading