Skip to content

Fix: Numeric properties are now correctly serialized as numbers#577

Open
cschwich wants to merge 2 commits intovictools:mainfrom
cschwich:bugfix/numeric-properties
Open

Fix: Numeric properties are now correctly serialized as numbers#577
cschwich wants to merge 2 commits intovictools:mainfrom
cschwich:bugfix/numeric-properties

Conversation

@cschwich
Copy link
Copy Markdown

@cschwich cschwich commented Apr 1, 2026

This PR fixes an issue where numeric properties (such as minLength) in the generated JSON Schema were incorrectly serialized as strings instead of numbers. The root cause was a misconfiguration of the ObjectMapper in versions < 5.0.0, where the WRITE_NUMBERS_AS_STRING feature was set but not actually applied. With the migration to Jackson 3 (from version 5.0.0), this bug was resolved, and the setting is now effective.

Changes

  • Ensure numeric properties in the schema are serialized as numbers
  • Adjust tests to verify the correct behavior

Fixed issues

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown
Member

@CarstenWickner CarstenWickner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cschwich

Thanks for pointing this out and the contribution.

If this affects the generator library in general, shouldn't the tests inside the main library be adjusted (where the change is) rather than on the Maven plugin?

Comment on lines +24 to +26

@Size(min = 1)
private String name;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why this change in the scope of the Maven plugin?
It's not particular to that plugin, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default ObjectMapper is used internally by the Maven plugin implementation and cannot easily be overridden there. In the other modules, the default ObjectMapper is currently not used in production code—only in some unit tests. However, you're absolutely right: developers who use the generator module directly might rely on the default ObjectMapper for serialization and run into the same issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just another thought: From my perspective, the correct location for the tests depends on what the intended responsibility of the generator module actually is.

If the generator module is meant to produce an in-memory representation of a JSON Schema (i.e., a Jackson JsonNode tree), then the generator itself is not responsible for serialization. In that case, testing the serialized output does not belong in the generator module, because serialization is simply not part of its contract.
With this interpretation, the Maven plugin — which uses a concrete ObjectMapper configuration to produce schema files — is the right place to test the final serialized JSON output.

On the other hand, if the generator module were to expose public APIs that produce serialized schema output directly, or if serialization were considered part of its public contract, then serialization tests would naturally belong there.

Since I have not found any API in the generator module that produces a serialized form, I assumed that the module’s responsibility were limited to generating the schema object tree. Based on that interpretation, placing the serialization tests in the Maven plugin module seemed appropriate.

@cschwich cschwich requested a review from CarstenWickner April 10, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants