import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
public class Test {
public static void main(String[] args) {
String json="{\"name\":\"zs\", \"department\":\"dev\", \"hobby\":\"basketball\"}";
ObjectMapper mapper = new ObjectMapper();
JavaTimeModule jtm=new JavaTimeModule ();
jtm.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
mapper.registerModule(jtm);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
try {
Employee ep = mapper.readValue(json, Employee.class);
System.out.println(ep.department);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}
class Employee{
String name;
String department;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}