Using this class structure
public class Customer{
private String name;
private String store;
private T details;
}
public class details{
private String dob;
private boolean validated;
}
It works when JSON is
{
"name": "John Smith",
"store": "Walmart",
"details": {
"dob": "1900/01/01",
"validated": true
}
}
But when given JSON responses below it fails.
{
"name": "John Smith",
"store": "Walmart",
"details": [
"Failed customer does not exist in the system", "Please contact administrator"
]
}
Is there anyway in Jackson mapper to handle these scenarios? If details is provided as pojo then write as such otherwise write details as a string value. I define my mapper as such
private static final ObjectMapper Mapper = new ObjectMapper() {{
setSerializationInclusion(JsonInclude.Include.NON_NULL);
setDateFormat(new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z", Locale.US));
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}};