I am using Jackson in Spring to serialize my class to JSON. When I serialize a class like the example below, Jackson is changing the names of certain fields from Camel Case to lower case. I know I can work around this by creating custom (de)serializers, yet I am hoping to turn this off globally. Perhaps by setting a property in application.properties.
Per the default Jackson naming strategy, this is not supposed to happen:
In absence of a registered custom strategy, default Java property naming strategy is used, which leaves field names as is...
class Foo {
private final String firstName;
private final String aName;
private final String name;
private final String abName;
Foo(final String firstName, final String aName, final String name, final String abName) {
this.firstName = firstName;
this.aName = aName;
this.name = name;
this.abName = abName;
}
// Getters here
}
public static void main(String[] args) {
final ObjectMapper mapper = new ObjectMapper();
final Foo foo = new Foo("first", "a", "name", "ab");
final String jsonInString = mapper.writeValueAsString(foo);
System.out.println(jsonInString);
}
Expected:
{"firstName":"first","name":"name","abName":"ab","aName":"a"}
Actual:
{"firstName":"first","name":"name","abName":"ab","aname":"a"}
EDIT:
Narrowed the problem down to interpretation of the getters. Starting to look like a bug in Jackson.
class Foo {
private final String aName;
Foo(final String aName) {
this.aName = aName;
}
public String getaName() {
return this.aName;
}
}
Serializes to {"aName":"a"}
However,
class Foo {
private final String aName;
Foo(final String aName) {
this.aName = aName;
}
public String getAName() {
return this.aName;
}
}
Serializes to {"aname":"a"}