I understand that I can create a map of a specified object with Jackson by using TypeReference. For instance, taking a class ...
public class Error {
/** Error code */
private final String errcode;
/** Error message */
private final String error;
// Getter
}
... and the data in JSON
{
"firstError":{
"errcode":"1234",
"error":"The 1. message"
},
"secondError":{
"errcode":"5678",
"error":"The 2. message"
}
}
... I can deserialize with
TypeReference<HashMap<String, Error>> typeRef = new TypeReference<HashMap<String, Error>>() {};
Map<String, Error> map = new ObjectMapper().readValue(jsonInput, typeRef);
My question is now: What can I do if my JSON looks like this?
{
"date":"2022-01-01",
"server":"myfancyserver",
"errors":{
"firstError":{
"errcode":"1234",
"error":"The 1. message"
},
"secondError":{
"errcode":"5678",
"error":"The 2. message"
}
}
}