fix: accept whole numbers for the formats float and double - #132
Merged
pk-work merged 1 commit intoAug 9, 2026
Merged
Conversation
The formats float and double define the precision of a number, not its representation. Jackson parses JSON numbers without a decimal part into Integer or Long, so values like 10 were rejected with 'Number does not match the format' although they are valid numbers with float or double precision. Whole numbers are now accepted for the formats float and double, as long as they can be represented exactly with the related precision (2^24 for float, 2^53 for double). The behaviour for all other instance types is unchanged. Fixes eclipse-vertx#112
pk-work
approved these changes
Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
As discussed in #112: the formats
floatanddoubledefine the precision of a number, not its lexical representation. Jackson parses JSON numbers without a decimal part intoInteger/Long, so a value like10for a{ "type": "number", "format": "float" }property was rejected withNumber does not match the format "float", although10is a valid number with float precision. This is a common real-world case, since many serializers emit25.0as25.Changes
Following the approach suggested in the issue discussion (relax the checks in
OpenAPIFormatValidator, bounded by the exactly representable integer range):Integer/Longinstances are now accepted for the formatsfloatanddouble, as long as the value is exactly representable with the related precision: |value| ≤ 2^24 forfloat, |value| ≤ 2^53 fordouble. Larger whole numbers are still rejected, so no information is lost silently.int32/int64checks).Test cases cover whole numbers for both formats (including the cases from #113), the exact-representability boundaries in both directions (
2^24/2^53accepted,2^24 + 1/2^53 + 1rejected), andInteger.MAX_VALUE/Long.MAX_VALUErejection.Fixes #112