Jackson Annotations - @JsonSetter
@JsonSetter memungkinkan metode tertentu untuk ditandai sebagai metode penyetel.
Contoh @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;
}
}
Keluaran
Marks