Fix: Numeric properties are now correctly serialized as numbers#577
Fix: Numeric properties are now correctly serialized as numbers#577cschwich wants to merge 2 commits intovictools:mainfrom
Conversation
|
CarstenWickner
left a comment
There was a problem hiding this comment.
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?
|
|
||
| @Size(min = 1) | ||
| private String name; |
There was a problem hiding this comment.
question: Why this change in the scope of the Maven plugin?
It's not particular to that plugin, right?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.



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
Fixed issues