Skip to content

maxLength and minLength do not work when a number with a zero decimal is used. #446

@mohsin-sq

Description

@mohsin-sq

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions