-
Notifications
You must be signed in to change notification settings - Fork 340
maxLength and minLength do not work when a number with a zero decimal is used. #446
Description
According to the json spec
1.0 and 1 are both considered integers, however the method used in max/minLength validations isIntegralNumber does not return true for 1.0. This has caused us some headaches as we are using proto3 to go from json -> proto3 and are running into the issue where when we set maxLength value to be 2, it get converted to 2.0 and does not get evaluated by the validators: https://github.com/networknt/json-schema-validator/blob/master/src/main/java/com/networknt/schema/MaxLengthValidator.java#L36
There was a recent issue where in jackson-databind which addressed this isIntegralNumber method and an canConvertToExactIntegral method was created for this exact purpose which should return true for both 2.0 and 2.
We propose updating the validators (something i can also do and send a pull request) where isIntegralNumber is used in the length validators (7 locations: https://github.com/networknt/json-schema-validator/search?q=isIntegralNumber)
References:
https://json-schema.org/understanding-json-schema/reference/numeric.html
FasterXML/jackson-databind#2885