I am getting the following JSON as response from a service. I am using Spring RestTemplate to call the service which also deserializes the JSON back into an Object. I am trying to deserialize it into an Object that has a List besides other fields. I am getting the following error while deserializing:
Can not instantiate value of type [simple type, class com.org.EmployeeInfo] from String value; no single-String constructor/factory method.
Following is the JSON that i want to deserialize:
{
"employees": {
"employeeInfo": [
"{\r\n \"id\": \"123\",\r\n \"group\": \"MARKETING\",\r\n \"role\": \"MANAGER\",\r\n}",
"{\r\n \"id\": \"256\",\r\n \"group\": \"IT\",\r\n \"role\": \"DIRECTOR\",\r\n}",
"{\r\n \"id\": \"789\",\r\n \"group\": \"SALES\",\r\n \"role\": \"CEO\",\r\n}"
]
},
"status": "EMPLOYED",
"somethingElse": {
"something": []
}
}
The default deserializer fails if i have the List<EmployeeInfo>
in the object that i try to map the respone to, but it works if i use List<String>
or String[]
. This is because of the double quotes in the JSON (I am talking about "{\r\n) which makes it treat as a String
I am planning to write a custom deserializer to deserialize it into an object having List and also remove the \r\n that's part of the response. How can i do that? Appreciate any responses.
Here are my POJOs:
public class Response {
private Employees employees;
private String status;
private SomethingElse somethingElse;
// getters, setters
}
public class Employees {
List<EmployeeInfo> employeeInfo;
// getters, setters
}
public class EmployeeInfo
{
private String id, group, role;
// getters, setters
}
Thanks