-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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."