Annotazioni Jackson - @JsonSetter
@JsonSetter consente di contrassegnare un metodo specifico come metodo setter.
Esempio @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;
}
}
Produzione
Marks