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
[BUG] @Getter and @Setter don't follow JavaBean naming convention #2650
Comments
This is a duplicate, and the maintainers have already stated they are not
going to address this.
See #1661 for background.
…On Wed, Nov 18, 2020 at 9:34 PM Giacomo Baso ***@***.***> wrote:
Suppose I have a field named oDo. For this field, lombok generates
methods getODo and setODo. I didn't question it at first, because it felt
the natural capitalization, however it's not actually compliant with JavaBean
naming convention
<https://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/>
.
According to 8.8: Capitalization of inferred names
to support the occasional use of all upper-case names, we check if the
first two characters of the name are both upper case and if so leave it
alone.
the getter getODo actually corresponds to a field name ODo. It follows
that the correct getter name for oDo is getoDo. Indeed, this is the
getter name generated by Eclipse, VS Code and I suppose other IDEs.
More importantly, it's the name used by Jackson to serialize fields,
therefore a class like:
@***@***.***@Jacksonizedclass Foo {
@JsonProperty("do")
private String oDo;
}
results in a duplicate serialization:
{
"do": "<value>",
"odo": "<value>"
}
Interestingly, @DaTa doesn't suffer from this problem because
@JsonProperty is copied onto the setter, making Jackson switch to that
getter/setter pair for serialization/deserialization.
See also:
https://stackoverflow.com/questions/26224938/getters-setters-when-first-word-has-second-letter-capitalized
Using jackson 1.18.16
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2650>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABIERP3PAVH3KEZCOLCGQTSQQVUTANCNFSM4T2O3VXA>
.
--
"Don't only practice your art, but force your way into it's secrets, for it
and knowledge can raise men to the divine."
-- Ludwig von Beethoven
|
Well, that's unfortunate. As a workaround, maybe |
If there are only a few fields affected, you can do this manually by adding |
That would work, but |
duplicate of #1661. PRs accepted, but make a plan on how to get from here to there and explain it to us first or we may have to reject it. |
Duplicate of #2693 |
Suppose I have a field named
oDo
. For this field, lombok generates methodsgetODo
andsetODo
. I didn't question it at first, because it felt the natural capitalization, however it's not actually compliant with JavaBean naming convention.According to 8.8: Capitalization of inferred names
the getter
getODo
actually corresponds to a field nameODo
. It follows that the correct getter name foroDo
isgetoDo
. Indeed, this is the getter name generated by Eclipse, VS Code and I suppose other IDEs.More importantly, it's the name used by Jackson to serialize fields, therefore a class like:
results in a duplicate serialization:
Interestingly,
@Data
doesn't suffer from this problem because@JsonProperty
is copied onto the setter, making Jackson switch to that getter/setter pair for serialization/deserialization.See also: https://stackoverflow.com/questions/26224938/getters-setters-when-first-word-has-second-letter-capitalized
Using jackson 1.18.16
The text was updated successfully, but these errors were encountered: