I have a simple POJO like
public class Employee
{
int level;
int salary;
Map<String, String> details; // HashMap
}
A serialized object of this class looks like
{"level":1,"salary":30000, "details":{"address":"ADDRESS", "phone":"12345678"}}
Assuming the above JSON string is stored in a Java String variable called json,
when deserializing it via the following Jackson statement
Employee employee = new ObjectMapper().readValue(json, Employee.class);
the object is properly created, no exception occurs, the fields “level” and “salary” are correctly populated, but the “details” field (originally a HashMap) is always null.
How can I correctly deserialize it?
Jackson correctly deserialized the details attribute with the version of Jackson that I have in my machine-1.8.1. Can you confirm that you have accessors created for Employee class, if not that could be the reason.