@Test public void propertiesAt() { ObjectNode node = newObject(); node.putArray("foo").add(newKvObject("k1", "v1")).add(newKvObject("k2", "v2")); Map<String, String> value = Selectors.propertiesAt(node, FOO_FIELD); assertThat(value, allOf(hasEntry("k1", "v1"), hasEntry("k2", "v2"))); }
public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isTextual()) { throw new WrongTypeException(pointer, "not a key-value pair at " + field); } properties.put(field.getKey(), field.getValue().asText()); } return properties; }
Selectors { public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isTextual()) { throw new WrongTypeException(pointer, "not a key-value pair at " + field); } properties.put(field.getKey(), field.getValue().asText()); } return properties; } }
Selectors { public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isTextual()) { throw new WrongTypeException(pointer, "not a key-value pair at " + field); } properties.put(field.getKey(), field.getValue().asText()); } return properties; }  }
Selectors { public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isTextual()) { throw new WrongTypeException(pointer, "not a key-value pair at " + field); } properties.put(field.getKey(), field.getValue().asText()); } return properties; }  static String textAt(JsonNode node, JsonPointer pointer); static int integerAt(JsonNode node, JsonPointer pointer); static Iterable<? extends JsonNode> listAt(JsonNode node, JsonPointer pointer); static List<String> textListAt(JsonNode node, JsonPointer pointer); static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer); }
Selectors { public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isTextual()) { throw new WrongTypeException(pointer, "not a key-value pair at " + field); } properties.put(field.getKey(), field.getValue().asText()); } return properties; }  static String textAt(JsonNode node, JsonPointer pointer); static int integerAt(JsonNode node, JsonPointer pointer); static Iterable<? extends JsonNode> listAt(JsonNode node, JsonPointer pointer); static List<String> textListAt(JsonNode node, JsonPointer pointer); static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer);  }