In my app I get JSON content as InputStream. Depending if its a single JSONObject or a JSONArray of those I want to perform different actions.
How can I differentiate, using Jackson, if it is an single object or an array of objects?
// cheers
SOLUTION:
Using JsonNote.isArray():
JsonNode rootNode = mapper.readValue(contentStream, JsonNode.class);
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
if(rootNode.isArray()){
// do something with the array
} else {
// do something else with the object
}
Just bind as either
java.lang.Object(and see if you got aListorMap); or asJsonNodeand callisObject()orisArray()on it?