Different names of JSON property during serialization and deserialization


Just tested and this works:

public class Coordinates {
    byte red;

    public byte getR() {
      return red;

    public void setRed(byte red) {
      this.red = red;

The idea is that method names should be different, so jackson parses it as different fields, not as one field.

Here is test code:

Coordinates c = new Coordinates();
c.setRed((byte) 5);

ObjectMapper mapper = new ObjectMapper();
System.out.println("Serialization: " + mapper.writeValueAsString(c));

Coordinates r = mapper.readValue("{\"red\":25}",Coordinates.class);
System.out.println("Deserialization: " + r.getR());


Serialization: {"r":5}
Deserialization: 25

You can use @jsonAlias which got introduced in jackson 2.9.0


public class Info {
  @JsonAlias({ "red" })
  public String r;

This uses r during serialization, but allows red as an alias during deserialization. This still allows r to be deserialized as well, though.

You can use a combination of @JsonSetter, and @JsonGetter to control the deserialization, and serialization of your property, respectively. This will also allow you to keep standardized getter and setter method names that correspond to your actual field name.

import com.fasterxml.jackson.annotation.JsonSetter;    
import com.fasterxml.jackson.annotation.JsonGetter;

class Coordinates {
    private int red;

    //# Used during serialization
    public int getRed() {
        return red;

    //# Used during deserialization
    public void setRed(int red) {
        this.red = red;