-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Comments
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. |
Thanks for raising this btw, particularly for the good detail and links. |
No problem. |
ref this issue: FasterXML/jackson-databind#653 and this one: https://bugs.eclipse.org/bugs/show_bug.cgi?id=322223 |
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:
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."
The text was updated successfully, but these errors were encountered: