I would like to use Jackson's Tree Model with Java 8 stream API, like so:
JsonNode jn = new ObjectMapper().readValue(src, JsonNode.class);
return jn.stream().anyMatch(myPredicate);
However, JsonNode does not seem to implement stream()
and I could not find any standard helpers to do so.
JsonNode
implements Iterable, so I can achieve the same results with Google Guava:
JsonNode jn = new ObjectMapper().readValue(src, JsonNode.class);
return Iterables.find(jn, myPredicate);
but what about pure Java solution?
JsonNode
implements Iterable
, so it has a spliterator()
. You can use
StreamSupport.stream(jn.spliterator(), false /* or whatever */);
to get a Stream
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With