I am trying to deserialize a string which is a JSON Array in Java using fasterxml. And I want to convert this into an ArrayList of JSONObjects.
[
{
"test": "hello"
},
{
"anotherTest": "world"
}
]
When I try to use the object mapper as follows,
ArrayList<JSONObject> list = mapper.readValue(sourceString, ArrayList.class);
I am getting an ArrayList which contains LinkedHashMap.
I tried to change my type using the below code.
ArrayList<JSONObject> list = mapper.readValue(s, mapper.getTypeFactory().constructCollectionType(List.class, JSONObject.class));
And even this...
ArrayList<JSONObject> list = mapper.readValue(s,new TypeReference<List<JSONObject>>() {});
Both it did not help me.
Any thoughts?