I'm trying to iterate through the elements in a JsonNode and check if they match some condition. I want to use Streams instead of using the classic iterator. I have code similar to this:
return Stream.generate(jsonNode.fields()::next)
.allMatch(entry -> {
switch (entry.getKey()) {
case "a":
return evaluateA(entry.getValue());
case "b":
return evaluateB(entry.getValue());
default:
return false;
}
});
But when I run this, I get a java.util.NoSuchElementException. I'm guessing the return statements within the switch case are causing this error. If that is the case, how do I handle this?