I have a problem while parsing JSON with Jackson. I have a POJO object, wrapped by another.
Here is my code:
in main:
ObjectMapper mapper = new ObjectMap
I wrote my own method, which parses JSON of such a structure.
Here is the code:
public static List parseList(String jsonInput, Class clazz) {
List result = new LinkedList();
JSONArray json = (JSONArray) JSONSerializer.toJSON(jsonInput);
JSONObject items = (JSONObject)json.getJSONObject(0);
JSONArray dataArrayJSON = (JSONArray)items.getJSONArray("items");
for (int i = 0; i < dataArrayJSON.size(); i++) {
result.add(JSONObject.toBean(dataArrayJSON.getJSONObject(i).getJSONObject("item"), clazz));
}
return result;
}
The problem was that items are in the array and items is the only element. items in its turn, is also an array, thus I used the dataArrayJSON.getJSONObject(i).getJSONObject("item")
construction.