-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Lombok with Jackson Deserializer from camelCase #1981
Comments
Are you sure this would work? I would expect Jackson to ignore that annotation on internal private fields of the builder class. At least it would be a bit surprising to me. But even if it works in Jackson, there is no easy way for Lombok to determine which annotation to put on the fields. For example, |
I would have hoped that |
Also looking at #1634, what if you have, annotations like |
Just for clarification: You want the annotation to be copied to the field, right? Because currently it is copied to the method's parameter, but Jackson does not recognise this. |
Correct, I want my Builder to look like public static final class UserBuilder {
@JsonProperty("user_name")
private String userName;
} And it makes sense that annotations like |
I just verified that (surprisingly) it works if the internal private field of the builder has the However, as stated above, IMO Lombok should not blindly copy all |
yes, the real issue is that 'copy that annotation where relevant' is insufficient information. With builder, there are at least 5 places we can copy it to:
We could blow copyableAnnotations apart into 5 things, but, copyableAnnotations is by design used by more lombok features which come with their own 'actually this could apply to multiple locations', so unless we're all okay with like 10+ copyableAnnotations config keys (and to be clear, we are not), this is one of those 'this is impossible' feature requests. What we can attempt to do is hardcode well known commonly used annotations, which is inelegant but them's the breaks. I'll look into hardcoding special behaviour for |
One unintended consequence of this is that mixins that worked before stopped working. Took a bit to figure out what was up, thought I would share with the class. Given an original file: @Data
public class Original {
@JsonProperty(access = Access.READ_ONLY)
private String someProperty;
} And a mixin like this: public class Mixin {
@JsonProperty(access = Access.READ_WRITE)
private String someProperty;
} And an Original augmentation new ObjectMapper()
.addMixIn(Original.class, Mixin.class)
.readValue("{\"someProperty\": \"someValue\"}", Original.class);
Now Lombok creates this bytecode on @Data
public class Original {
@JsonProperty(access = Access.READ_ONLY)
private String someProperty;
@JsonProperty(access = Access.READ_ONLY)
public String getSomeProperty() {
return someProperty;
}
@JsonProperty(access = Access.READ_ONLY)
public String setSomeProperty(String someProperty) {
this.somePropety = someProperty;
}
} Since the mixin does not have Fix is to ensure that your mixin also has public class Mixin {
@Getter
@Setter
@JsonProperty(access = Access.READ_WRITE)
private String someProperty;
} |
Here is a simple Object
Now, if I want to use ObjectMapper to read a string to this, I do
But this does not read the user_name because when I look at the generated source code for the builder, I see
And so the camelCase doesn't match the snake_case.
Normally if I were to manually generate the Builder class, I would put
@JsonProperty("user_name")
on the builder property as well:How do I fix this? I want the Builder fields to also get the
@JsonProperty
annotation.The text was updated successfully, but these errors were encountered: