I have an object stored in String. One of the fields of the object is LocalDate.
"from": {
"year": 1000,
"month": "JANUARY",
"era": "CE",
"dayOfMonth": 1,
"dayOfWeek": "WEDNESDAY",
"dayOfYear": 1,
"leapYear": false,
"monthValue": 1,
"chronology": {
"calendarType": "iso8601",
"id": "ISO"
}
}
How do I convert this json to a format that can be used for deserialization?
Following code
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
ObjectMapper om = new ObjectMapper();
om.registerModule(new JavaTimeModule());
MyCustomObject obj = om.readValue(json, MyCustomObject.class);
throws this exception:
com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (START_OBJECT), expected VALUE_STRING: Expected array or string.
Here's the MyCustomObject class, which I use as MyCustomObject <LocalDate>
public class MyCustomObject<T> {
private T from;
private T to;
public MyCustomObject() {
}
public T getFrom() {
return this.from;
}
public void setFrom(T from) {
this.from = from;
}
public T getTo() {
return this.to;
}
public void setTo(T to) {
this.to = to;
}
}
source
share