DataJsonNode { public List<DataJsonNode> collectChildrenFromRoot(){ List<DataJsonNode> dataJsonNode = new ArrayList<>(); dataJsonNode.add(this); this.collectChildrenDeep(dataJsonNode); return dataJsonNode; } DataJsonNode(ObjectNode jsonNode); void removeAttribute(String name); String getDataClassName(); boolean match(String dataClassNameFullQualified); void renameAttribute(String previousAttributeName, String newAttributeName); void renameClass(Class<? extends FactoryBase<?,?>> newDataClass); DataJsonNode getChild(String attributeName); DataJsonNode getChild(String attributeName, int index); JsonNode getAttributeValue(String attribute); void setAttributeValue(String attribute, JsonNode jsonNode); V getAttributeValue(String attributeName, Class<V> valueClass, SimpleObjectMapper simpleObjectMapper); V getArrayAttributeValue(String attributeName, Class<V> valueClass, SimpleObjectMapper simpleObjectMapper, int index); String getAttributeIdValue(String attributeName); boolean isData(); List<DataJsonNode> collectChildrenFromRoot(); String getId(); D asData(Class<D> valueClass, SimpleObjectMapper simpleObjectMapper); List<String> getAttributes(); Map<String,DataJsonNode> collectChildrenMapFromRoot(); Map<String,DataJsonNode> collectChildrenMapFromRootCached(); void applyRemovedAttribute(DataStorageMetadataDictionary dataStorageMetadataDictionary); void applyRetypedAttribute(DataStorageMetadataDictionary dataStorageMetadataDictionary); void applyRemovedClasses(DataStorageMetadataDictionary dataStorageMetadataDictionary); void fixIdsDeepFromRoot(Map<String, DataJsonNode> idToChild); JsonNode getJsonNode();  }
@Test public void test_getChildrenFromRoot_simple() { ExampleDataA exampleDataA = new ExampleDataA(); ExampleDataB value = new ExampleDataB(); exampleDataA.referenceAttribute.set(value); value.referenceAttributeC.set(new ExampleDataC()); exampleDataA.referenceListAttribute.add(new ExampleDataB()); JsonNode jsonNode = ObjectMapperBuilder.build().writeValueAsTree(exampleDataA); DataJsonNode dataJsonNode = new DataJsonNode((ObjectNode) jsonNode); List<DataJsonNode> childrenFromRoot = dataJsonNode.collectChildrenFromRoot(); Assertions.assertEquals(4, childrenFromRoot.size()); }
@Test public void test_getChildrenFromRoot_loop() { ExampleDataA exampleDataA = new ExampleDataA(); ExampleDataB value = new ExampleDataB(); exampleDataA.referenceAttribute.set(value); value.referenceAttribute.set(exampleDataA); JsonNode jsonNode = ObjectMapperBuilder.build().writeValueAsTree(exampleDataA); DataJsonNode dataJsonNode = new DataJsonNode((ObjectNode) jsonNode); List<DataJsonNode> childrenFromRoot = dataJsonNode.collectChildrenFromRoot(); Assertions.assertEquals(2, childrenFromRoot.size()); }
@Test public void test_getChildrenFromRoot_ref() { ExampleDataA exampleDataA = new ExampleDataA(); ExampleDataB value = new ExampleDataB(); exampleDataA.referenceAttribute.set(value); value.referenceAttributeC.set(new ExampleDataC()); exampleDataA.referenceListAttribute.add(value); JsonNode jsonNode = ObjectMapperBuilder.build().writeValueAsTree(exampleDataA); DataJsonNode dataJsonNode = new DataJsonNode((ObjectNode) jsonNode); List<DataJsonNode> childrenFromRoot = dataJsonNode.collectChildrenFromRoot(); Assertions.assertEquals(3, childrenFromRoot.size()); }