I retrieve a JSON string from internet; like most JSON I've seen it includes long keys that are separated by underscores. Essentially, my goal is to deserialize JSON into java-objects, but I don't use underscores in java-code.
For instance, I might have a User
class with firstName
field in camel-case, simultaneously I need somehow to tell Jackson to map first_name
key from JSON to firstName
class field. Is it possible?
class User{
protected String firstName;
protected String getFirstName(){return firstName;}
}
Best Answer
You can configure the
ObjectMapper
to convert camel case to names with an underscore:Or annotate a specific model class with this annotation:
Before Jackson 2.7, the constant was named: