Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Jackson support java 8 stream()?

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?

like image 374
vitaly Avatar asked May 21 '15 21:05

vitaly


1 Answers

JsonNode implements Iterable, so it has a spliterator(). You can use

StreamSupport.stream(jn.spliterator(), false /* or whatever */);

to get a Stream.

like image 175
Sotirios Delimanolis Avatar answered Oct 03 '22 20:10

Sotirios Delimanolis