Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Java 8 Stream from ArrayNode

Is it possible to create stream from com.fasterxml.jackson.databind.node.ArrayNode?
I tried:

ArrayNode files = (ArrayNode) json.get("files"); Stream<JsonNode> stream = Stream.of(files); 

But it will actually give stream of one element, the initial ArrayNode object.
Correct result should be Stream<JsonNode>, can I achieve it?

like image 218
icl7126 Avatar asked Sep 20 '15 20:09

icl7126


1 Answers

ArrayNode implements Iterable. Iterable has a spliterator() method. You can create a sequential Stream from a Spliterator using

StreamSupport.stream(spliterator, false) 
like image 50
JB Nizet Avatar answered Sep 24 '22 06:09

JB Nizet