Fork me on GitHub
#other-languages
<
2021-05-14
>
teodorlu12:05:43

Does jackson (Java) provide a get-in equivalent for lookup on a JsonNode?

teodorlu10:05:29

In case anyone else are interested, I just wrote it out:

JsonNode current = this.provideJson.get();

        for (String k : key) {
            if (current.hasNonNull(k)) {
                current = current.get(k);
            } else {
                return Optional.empty();
            }
        }

        if (current.isInt())
            return Optional.of(current.asInt());
        else
            return Optional.empty();
Quite straightforward.

teodorlu10:05:01

Different methods for different types. I didn't bother with generics.

osi20:05:47

JsonNode#at is it’s built-in equivalent

💯 3
3