Jackson Annotations 简明教程

Jackson Annotations - @JsonSetter

@JsonSetter 允许标记特定的方法为 setter 方法。

Example @JsonSetter

import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JacksonTester {
   public static void main(String args[]){
      ObjectMapper mapper = new ObjectMapper();
      String jsonString = "{\"rollNo\":1,\"name\":\"Marks\"}";

      try {
         Student student = mapper.readerFor(Student.class).readValue(jsonString);
         System.out.println(student.name);
      }
      catch (IOException e) {
         e.printStackTrace();
      }
   }
}
class Student {
   public int rollNo;
   public String name;
   @JsonSetter("name")
   public void setTheName(String name) {
      this.name = name;
   }
}

Output

Marks