Issue
TypeFactory uses jackson-databind's JsonNode.isIntegralNumber and JsonNode.isNumber to see if the node's type is integer or number, respectively. This result is used when comparing node type and schema type which is not precise enough in some cases.
|
if (node.isIntegralNumber()) |
|
return JsonType.INTEGER; |
|
if (node.isNumber()) |
|
return JsonType.NUMBER; |
Scenario
Assume that we have a schema where a property's type is integer.
Given a DecimalNode(v) where v is a value that can fit into Long, json-schema-validator thinks that node type is number and this results in type failure as number found, integer expected
Proposal
Update line 72-73 in the snippet above as following (canConvertToLong() is defined for DecimalNode at jackson-databind)
if (node.isIntegralNumber() || node.canConvertToLong())
return JsonType.INTEGER;
so that we can have a validator with better precision
Issue
TypeFactory uses
jackson-databind'sJsonNode.isIntegralNumberandJsonNode.isNumberto see if the node's type is integer or number, respectively. This result is used when comparing node type and schema type which is not precise enough in some cases.json-schema-validator/src/main/java/com/networknt/schema/TypeFactory.java
Lines 72 to 75 in 4ba09d5
Scenario
Assume that we have a schema where a property's type is
integer.Given a
DecimalNode(v)wherevis a value that can fit intoLong, json-schema-validator thinks that node type isnumberand this results in type failure asnumber found, integer expectedProposal
Update line 72-73 in the snippet above as following (
canConvertToLong()is defined forDecimalNodeatjackson-databind)so that we can have a validator with better precision