Same properties are parsed multiple times when variable name is capitalized and JsonProperty annotated
See original GitHub issueI have created a repo for this bug. See here: https://github.com/dentych/jackson-bug
In short terms, the issue is that variables in caps (e.g. MAT) that is annotated with JsonProperty(“MAT”) will be in the serialized JSON string twice.
The example output from my reproduction: The POJO “MyCollection”:
class MyCollection {
@JsonProperty("MAT")
private MAT MAT = null;
@JsonProperty("DAR")
private DAR DAR = null;
@JsonProperty("someString")
private String someString = null;
public MAT getMAT() {
return MAT;
}
public void setMAT(MAT MAT) {
this.MAT = MAT;
}
public DAR getDAR() {
return DAR;
}
public void setDAR(DAR DAR) {
this.DAR = DAR;
}
public String getSomeString() {
return someString;
}
public void setSomeString(String someString) {
this.someString = someString;
}
}
MAT and DAR are two simple POJOs that includes a propery “String name”. Each have getter and setters for the string.
When parsed, the following is output:
value =
{
"mat": {
"name": "MAT object"
},
"dar": {
"name": "DAR object"
},
"MAT": {
"name": "MAT object"
},
"DAR": {
"name": "DAR object"
},
"requestedBFE": "101262"
}
As you can see, MAT and DAR are both present as they should, but there’s also a mat and a dar that should not be present.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why does Jackson 2 not recognize the first capital letter if the ...
The problem you are seeing is due to the fact that Jackson uses Java Bean naming conventions to figure out the the Json...
Read more >More Jackson Annotations - Baeldung
This article covers some lesser-known JSON processing annotations ... All name elements, including the first one, start with a capitalized ...
Read more >Definitive Guide to Jackson ObjectMapper - Serialize and ...
In this detailed guide - learn everything you need to know about ObjectMapper. Convert JSON to and from Java POJOs, implement custom ...
Read more >Solving the XML Problem with Jackson - Stackify
Looking for a mature, flexible way of working with both JSON and XML for the same data? Read how the Jackson XML module...
Read more >picocli - a mighty tiny command line interface
Picocli has separate annotations for options and positional parameters. 3.1. Options. An option must have one or more names . Picocli lets you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dentych Thank you for verifying. This is the recommended way to deal with this situation then – for Jackson 3.0 we can and will change the defaults as well, to avoid having to configure mapper this way.
@cowtowncoder Using
MapperFeature.USE_STD_BEAN_NAMING
made it output the correct values and only once each.