-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
one initial lower case named variables does not get properly serialized when named with JsonProperty #2868
Comments
I am not sure there is a way to resolve this, generally: as far as I know, something like
can only be mangled to either However: I am hoping to work bit more on #2624 (and esp. #2800) to allow ways for users to be able to customize handling. In the meantime the way to resolve it for specific case is to add |
Yes, I understand that this is a hard nut to crack, but it very well may be that the case-insensitive strategy can be a solution as a setting on the objectMapper, maybe even with a setting (fromAccessors/fromFields) even if I'm unsure how compatible this would be with the current configuration system.
And as you say and to correct my initial report, there are easy ways to work around the problem (add a getter with @JsonProperty or just avoid using aTest-like variable names), so the main issue is that the behavior may turn up without anyone noticing it until it is (potentially) too late. And I guess a case-insensitive strategy would only partly help with that as long as it not enabled by default. In our case though we are using an objectMapper which is configured identically in all our code bases, so it would be a step in the right direction to detect this once and then "fix" it on the mapper configuration level. |
The problem here is that the way Lombok typically works is not the way Jackson's handling has existed since the beginning -- it starts with field name, usually, trying to determine accessor name. Jackson starts with accessor name(s), trying to match that to field name. Jackson 2.12.0 will include #2800 (pluggable |
Thank you for fast and excellent feedback, and for maintaining this excellent library. I'm looking forward to the 2.12.0 release! |
Describe the bug
When using @JsonProperty("some_other_name") on a variable that starts with an initial lower case letter followed directly by an uppercase letter (for example aProp), the property gets duplicated when serializing the object. Once as "some_other_name", and once as "aprop". MapperFeature.USE_STD_BEAN_NAMING does not fix this, the only change is that the other property now is named AProp instead. The only way to fix this seems to be to name the getter getaProp(), which does not follow the Java Bean convention of capitalizing the first letter, and e.g. lombok does not do it this way.
Version information
Which Jackson version(s) was this for?
2.11.2
To Reproduce
Expected behavior
There should only be one property, "renamed".
Additional context
As we use lombok to create accessors, we cannot solve it in as in MyFixedTroublesomeObject above.
The text was updated successfully, but these errors were encountered: