Reputation: 3242
I don't know how Jackson deserializes. I have a JSON and only need certain parts.
ObjectMapper mapper = new ObjectMapper();
How would the performance vary between:
mapper.readerFor(Integer.class).at("/code").readValue(inputStream);
mapper.reset();
mapper.readerFor(MyClass[].class).at("/level1/level2").readValue(inputStream);
vs
Reading the entire JSON:
mapper.readValue(inputStream, Map.class);
Upvotes: 0
Views: 441
Reputation: 769
Since key order in a JSON object is not fixed there's no way to know where the needed key exists in the input stream.
In the worst case scenario the entire stream has to be parsed if the desired key is last. On average when reading a single key there's a potential performance boost possible but benchmarking is the sure way to find out on the data you're using.
Upvotes: 1