[Solved] Inherit model with different JSON property names


One way is to use PropertyNamingStrategy http://wiki.fasterxml.com/PropertyNamingStrategy

Here is nice simple demo how you can use it Link to How to Use PropertyNamingStrategy in Jackson


The other is use MixInAnnotations
http://wiki.fasterxml.com/JacksonMixInAnnotations

with MixInAnnotations you can create just one Person class and Mixin for any other alternative property name setup.

public static void main(String[] args) throws IOException {
    ObjectMapper mapper1 = new ObjectMapper();
    String person1 = "{\"firstName\":null,\"lastName\":null,\"address\":null}";
    Person deserialized1 = mapper1.readValue(person1,Person.class);

    ObjectMapper mapper2 = new ObjectMapper();
    mapper2.addMixIn(Person.class, PersonMixin.class);
    String person2 = "{\"fName\":null,\"lName\":null,\"addr\":null}";
    Person deserialized2 = mapper2.readValue(person2,Person.class);
}

public static class Person {
    @JsonProperty("firstName")
    String firstName;
    @JsonProperty("lastName")
    String lastName;
    @JsonProperty("address")
    String address;

}

public class PersonMixin {
    @JsonProperty("fName")
    String firstName;
    @JsonProperty("lName")
    String lastName;
    @JsonProperty("addr")
    String address;
}

solved Inherit model with different JSON property names