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

The generated POJO does not always adhere to JavaBean naming conventions #756

Closed
chris-doclily opened this issue Jun 29, 2017 · 4 comments
Closed
Labels
Milestone

Comments

@chris-doclily
Copy link

I'm not sure whether you consider this a bug, but when a field's first component in a camelCase name is one character long, the POJO that gets generated doesn't adhere to JavaBean naming conventions, which can cause JSON converters such as Jackson to fail to convert JSON to the POJO.
This schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "GetDoximityVerificationUrlRequest",
    "type": "object",
    "properties": {
        "oAuth2State": { "type": "string" }
    },
    "required": ["oAuth2State"]
}

results in a class with a field with the name "oAuth2State" and a setter with the name "setOAuth2State." According to http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf?AuthParam=1498709191_3dace9f64de0156afa4efacc2d44e2f9, section 8.8, the fact that the "OAuth2State" in "setOAuth2State" starts with two capital letters means that it should correspond to a field named "OAuth2State" rather than "oAuth2State". The setter for a field named "oAuth2State" has to be "setoAuth2State" in order to adhere to the JavaBeans convention. Jackson sees "oAuth2State" in some JSON and expects to see a setter named "setoAuth2State."

This SO post talks about the naming conventions: https://stackoverflow.com/questions/8969112/confused-about-naming-of-javabean-properties-with-respect-to-getters-and-setter .
I posted the code where Jackson and AWS Lambda were failing to do a conversion in this issue: aws/aws-sdk-java#1213

Enabling Jackson annotations in jsonschema2pojo fixes the problem for Jackson, but I don't think that's a complete solution. In my case, it does not fix the problem for whatever code AWS Lambda uses to convert JSON input to POJOs.

I worked around the issue by renaming the property. This issue isn't a big deal, but I think there's an improvement to consider, if only because it will save time for developers who have never encountered this issue with JavaBean naming conventions. Note that, when I ask IntelliJ to generate a setter for a class's "oAuth2State" field, it names the setter "setoAuth2State."

@chris-doclily chris-doclily changed the title The generated POJO does not adhere to JavaBean naming conventions when a camelCase property's component is one letter long. The generated POJO does not always adhere to JavaBean naming conventions Jun 29, 2017
@joelittlejohn
Copy link
Owner

I wasn't aware of this extra naming rule. That's really interesting. I'm a little surprised that such a naive rule is defined by the spec.

We should fix this I think, but this could be quite a major breaking change for some people. I might at least bump to 0.5.0 for this.

I'm surprised this hasn't been raised before now.

@joelittlejohn
Copy link
Owner

Thanks for raising this btw, particularly for the good detail and links.

@chris-doclily
Copy link
Author

No problem.

@joelittlejohn joelittlejohn modified the milestones: 0.5.0, 1.0.0 Jul 18, 2017
@joelittlejohn joelittlejohn modified the milestones: 1.0.0, 1.0.0-alpha2 Feb 3, 2018
@joelittlejohn
Copy link
Owner

joelittlejohn commented Feb 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants