If I have a JSON string, and want to make two instances of a Jackson JsonNode from it. Should I create one with ObjectMapper.readTree(<json_string>), and then create a copy with <first_instance>.deepCopy(), or do the ObjectMapper.readTree(<json_string>) again?
This:
String inputJson = "<a bunch of JSON>";
ObjectMapper mapper = new ObjectMapper();
JsonNode instance1 = mapper.readTree(inputJson);
JsonNode instance2 = mapper.readTree(inputJson);
or this:
String inputJson = "<a bunch of JSON>";
ObjectMapper mapper = new ObjectMapper();
JsonNode instance1 = mapper.readTree(inputJson);
JsonNode instance2 = instance1.deepCopy();
It seems to me that the string parsing in readTree() is likely to be far more costly than the copying in deepCopy() of whatever objects hold the contents under the hood in the JsonNode class.
But I just want to see if anyone's confirmed this.