IntToStringKeyFilter extends AbstractFilter<ObjectNode, ObjectNode> { @Override protected ObjectNode doFilter(ObjectNode node) throws FilterException { JsonNode keyNode = node.at(source.getDomainIdKey()); if (keyNode.isTextual()) return node; JsonNode parentNode = node.at(parentPointer); if (parentNode.isObject()) { ((ObjectNode) parentNode).put(keyName, keyNode.asText()); } else if (parentNode.isArray()) { ((ArrayNode) parentNode).insert(Integer.valueOf(keyName), keyNode.asText()); } else { throw new IllegalArgumentException("failed to find parent node for domainIdKey"); } return node; } @Inject  IntToStringKeyFilter(
			@Assisted DataSource source,
			MetricRegistry registry);   }
@Test public void testObjectParentNode() throws Exception { DataSource source = createDataSource("/parent/id"); ObjectNode baseNode = new ObjectNode(JsonNodeFactory.instance); ObjectNode parentNode = baseNode.putObject("parent"); parentNode.put("id", 10); ObjectNode resultNode = new IntToStringKeyFilter(source, registry).doFilter(baseNode); Assert.assertTrue(resultNode.path("parent").path("id").isTextual()); }
@Test public void testArrayParentNode() throws Exception { DataSource source = createDataSource("/parent/0"); ObjectNode baseNode = new ObjectNode(JsonNodeFactory.instance); ArrayNode parentNode = baseNode.putArray("parent"); parentNode.add(10); ObjectNode resultNode = new IntToStringKeyFilter(source, registry).doFilter(baseNode); Assert.assertTrue(resultNode.path("parent").get(0).isTextual()); }