Ich habe ein Objekt in einem String gespeichert. Eines der Felder des Objekts ist ein LocalDate.Wie konvertiere ich einen JSON, der ein LocalDate-Feld enthält, in ein deserialisierbares Format?
"from": {
"year": 1000,
"month": "JANUARY",
"era": "CE",
"dayOfMonth": 1,
"dayOfWeek": "WEDNESDAY",
"dayOfYear": 1,
"leapYear": false,
"monthValue": 1,
"chronology": {
"calendarType": "iso8601",
"id": "ISO"
}
}
Wie soll ich dieses json in ein Format konvertieren, das für die Deserialisierung verwendet werden kann?
Der folgende 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); //error
Ursachen dieser Ausnahme:
com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (START_OBJECT), expected VALUE_STRING: Expected array or string.
Hier ist die MyCustomObject Klasse, die ich als MyCustomObject verwenden <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;
}
}
Können Sie Ihren 'MyCustomObject' Code teilen? –