Stop Jackson from changing case of variable names
You can also use PropertyNamingStrategy option in Objectmapper.
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE)
The problem here is more about JavaBeans(TM) Specification. According to the spec (page 58)
However 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
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”
And you have an edge case with aName
field . Because if the getter looks like AName()
, then when you convert back from this getter you should look for AName
field according to the specification. Here is additional info explanation
So to fix this, you can use a proper getter(getaName()
) or @JsonProperty("aName")
annotation above field/getter
Here is similar question
Although I'm not sure why Jackson reads getAName
to aname
, it's possible to force a Jackson to use a certain name with @JsonProperty("AName")
. For example:
class Foo {
private final String aName;
Foo(final String aName) {
this.aName = aName;
}
@JsonProperty("AName")
public String getAName() {
return this.aName;
}
}
(Got this solution from this closely related question.)