Skip to content

fix: accept whole numbers for the formats float and double - #132

Merged
pk-work merged 1 commit into
eclipse-vertx:mainfrom
SiteNetSoft:fix/number-format-validation
Aug 9, 2026
Merged

fix: accept whole numbers for the formats float and double#132
pk-work merged 1 commit into
eclipse-vertx:mainfrom
SiteNetSoft:fix/number-format-validation

Conversation

@jnbdz

@jnbdz jnbdz commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Motivation

As discussed in #112: the formats float and double define the precision of a number, not its lexical representation. Jackson parses JSON numbers without a decimal part into Integer/Long, so a value like 10 for a { "type": "number", "format": "float" } property was rejected with Number does not match the format "float", although 10 is a valid number with float precision. This is a common real-world case, since many serializers emit 25.0 as 25.

Changes

Following the approach suggested in the issue discussion (relax the checks in OpenAPIFormatValidator, bounded by the exactly representable integer range):

  • Integer/Long instances are now accepted for the formats float and double, as long as the value is exactly representable with the related precision: |value| ≤ 2^24 for float, |value| ≤ 2^53 for double. Larger whole numbers are still rejected, so no information is lost silently.
  • The behaviour for all other instance types is unchanged (including the NaN/Infinity rejection and the int32/int64 checks).

Test cases cover whole numbers for both formats (including the cases from #113), the exact-representability boundaries in both directions (2^24/2^53 accepted, 2^24 + 1/2^53 + 1 rejected), and Integer.MAX_VALUE/Long.MAX_VALUE rejection.

Fixes #112

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
pk-work merged commit a2e2dc1 into eclipse-vertx:main Aug 9, 2026
5 checks passed
@jnbdz
jnbdz deleted the fix/number-format-validation branch August 12, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request validation fails for arguments expecting a Float when the input has no decimal part

2 participants