I need to parse the same json stream twice, one time to identify say the length of array in the json stream, and next to parse the entities. However, there is only a single instance of JsonParser to start with. Is there a way I can clone this or create a copy of this because once the instance is used to parse, it can't be reused for re-parsing the same json stream obviously. Thanks in advance.
Example:
static class ResultEntitiesContainer {
List<ResultEntity> resultEntities;
// getter and setters available
}
void parseEntities(JsonParser parser) {
// Need to extract number of entities.
int count=0;
ObjectMapper om = new ObjectMapper();
JsonNode node = om.readTree(parser);
node = node.get("resultEntities");
if (node.isArray()) {
count = node.size();
}
// Need to parse the entities in the json node
ResultEntitiesContainer rec = om.readValue(parser, ResultEntitiesContainer.class);
}