Fix #1669: JSR 303 annotations on array types #1670
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.
This is a (relatively) straightforward fix of the issue where JSR 303 annotations are not generated for array types. Closes #1669.
For example, the schema...
...should generate a
@Size
annotation on thebytes
field due to the presence ofminLength
andmaxLength
, but it does not.The core issue was that the code (quite reasonably) assumed that
JType#fullName()
would always return values that could subsequently be loaded byClass#forName()
, modulo any type parameters. However, for arrays (e.g., byte arrays),JType#fullName()
would returnbyte[]
, whereasClass#forName()
expects[B
. Simply checking for array types usingJType#isArray()
before inspecting names fixes the issue.Fix includes tests.
Hopefully this all makes sense! Please send all questions, comments, and thoughts my way, and I will address ASAP.
Thank you building and continuing to maintain
jsonschema2pojo
!