-
-
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
Duplicate properties with upper-case field name and JsonProperty annotation #1609
Comments
Not a bug but results from incompatible field/getter/setter naming -- fields would imply properties Fortunately there is a simple fix: just move annotations to either setters or getters (either one is fine): this will allow otherwise separate fields and getter/setter pairs to match |
Why this works well? Fields introduce private static class Person {
Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@JsonProperty("Name")
private String name;
@JsonProperty("Age")
private int age;
} |
It works because all accessors initially match: "getAge()", "setAge()" and "age" infer |
I have an instance where for below fields in my pojo:
During conversion from POJO to json it introduces new field: ocurrNod apart from the original field oCurrNod. Can you please comment on why would this be even though this naming convention seems to be right? I also tried adding @JsonProperty annotation to getter to see if that fixes as suggested above in the comments. But this change doesn't fix the issue. I am using jackson 2.4.4 |
@ronikraja Please use mailing list: https://groups.google.com/forum/#!forum/jackson-user for usage questions. Adding questions on closed issues is not a good medium for those. But I can speculate on the problem: names are not compatible, due to inconsistent capitalization of the first 2 letters (field has 1; accessors 2). |
mark |
In some case, Jackson will duplicate entries when the annotation is on field See FasterXML/jackson-databind#1609
* Move Jackson annotation from field to getter In some case, Jackson will duplicate entries when the annotation is on field See FasterXML/jackson-databind#1609 * Update samples
Duplicate properties with upper-case field name and JsonProperty annotation
Expected:
com.fasterxml.jackson.databind.ser.BeanSerializerFactory:138
Neal
The text was updated successfully, but these errors were encountered: