How to map JSON field names to different object field names? How to map JSON field names to different object field names? json json

How to map JSON field names to different object field names?


Probably it's a bit late but anyway..

you can rename a property just adding

@JsonProperty("contractor")

And by default Jackson use the getter and setter to serialize and deserialize.

For more detailed information: http://wiki.fasterxml.com/JacksonFAQ


With some example, You can also use it in getter and setter to rename it to different field

public class Sample {    private String fruit;    @JsonProperty("get_apple")    public void setFruit(String fruit) {        this.fruit = fruit;    }    @JsonProperty("send_apple")    public String getFruit() {        return fruit;    }}


Please note that the proper JavaEE API for this is to use the javax.json.bind.annotation.JsonbProperty annotation. Of course Jackson and others are just some implementations of the JSON Binding API, they will likely comply with this.