AbstractNode { @Nonnull public Map<String, N> getObjectValues() { checkObject(); Map<String, N> objectValues = new LinkedHashMap<>(node.size()); Iterator<String> fieldNames = node.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); objectValues.put(fieldName, newNode(node.get(fieldName))); } return objectValues; } AbstractNode(JsonNode node); @Nonnull List<N> getArrayValues(); @Nonnull Map<String, N> getObjectValues(); @Nonnull N getObject(@Nonnull String fieldName); N getObject(@Nonnull String fieldName, @Nullable N def); N getArray(@Nonnull String fieldName); N getArray(@Nonnull String fieldName, @Nullable N def); int getAsInt(@Nonnull String fieldName); int getAsInt(@Nonnull String fieldName, int def); BigInteger getAsBigInt(@Nonnull String fieldName); BigInteger getAsBigInt(@Nonnull String fieldName, BigInteger def); long getAsLong(@Nonnull String fieldName); boolean getAsBoolean(@Nonnull String fieldName); Boolean getAsBoolean(@Nonnull String fieldName, @Nullable Boolean def); @Nonnull String getAsString(@Nonnull String fieldName); String getAsString(@Nonnull String fieldName, @Nullable String def); @Nonnull String getAsString(); boolean isNull(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void getObjectValues() { AbstractNode<N> node = objectNode(pair("A", "1"), pair("B", "2"), pair("C", "3")); Map<String, String> values = node.getObjectValues().entrySet().stream(). collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getAsString())); assertThat(values).containsExactly(entry("A", "1"), entry("B", "2"), entry("C", "3")); assertThat(emptyNode().getObjectValues()).isEmpty(); }
@Test public void getObjectValuesNotAnObject() { assertThatExceptionOfType(NodeProcessingException.class). isThrownBy(() -> stringArrayNode("A", "B", "C").getObjectValues()); assertThatExceptionOfType(NodeProcessingException.class). isThrownBy(() -> stringNode("A").getObjectValues()); }