Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1669: JSR 303 annotations on array types #1670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sigpwned
Copy link

@sigpwned sigpwned commented Mar 5, 2025

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...

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "BinaryImageAttributes",
  "type": "object",
  "properties": {
    "bytes": {
      "type": "string",
      "media": {
        "binaryEncoding": "base64"
      },
      "description": "Base64-encoded binary image data.",
      "minLength": 1,
      "maxLength": 102400
    }
  },
  "required": ["bytes"]
}

...should generate a @Size annotation on the bytes field due to the presence of minLength and maxLength, 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 by Class#forName(), modulo any type parameters. However, for arrays (e.g., byte arrays), JType#fullName() would return byte[], whereas Class#forName() expects [B. Simply checking for array types using JType#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!

…pes when minLength and/or maxLength are present
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.

BUG: JSR 303 annotations not generated for array types when minLength and/or maxLength are present
1 participant