@Test public void testTranslateObjectArrayField() throws Exception{ ObjectArrayElement oae = new ObjectArrayElement(); oae.getFields().addNew(new SimpleField("uid", StringType.TYPE)); EntityMetadata md = fakeEntityMetadata("fakeMetadata", new ArrayField("objArr", oae)); FakeTranslatorToJson<SingleFieldObject<SingleFieldObject<String>[]>> translator = new FakeTranslatorToJson<SingleFieldObject<SingleFieldObject<String>[]>>(factory, md) { @Override protected Object getValueFor(Object source, Path path) { if (source instanceof SingleFieldObject) { return ((SingleFieldObject<?>) source).value; } throw new RuntimeException("Unexpected"); } }; @SuppressWarnings("unchecked") JsonDoc json = translator.translate(new SingleFieldObject<>(new SingleFieldObject[]{ new SingleFieldObject<>("fake value1"), new SingleFieldObject<>("fake value2")})); assertNotNull(json); JSONAssert.assertEquals("{\"objArr\":[{\"uid\":\"fake value1\"},{\"uid\":\"fake value2\"}]}", json.toString(), true); }
public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } return null; }
TranslatorToJson { public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } return null; } }
TranslatorToJson { public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } return null; } TranslatorToJson(JsonNodeFactory factory, EntityMetadata entityMetadata); }
TranslatorToJson { public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } return null; } TranslatorToJson(JsonNodeFactory factory, EntityMetadata entityMetadata); JsonDoc translate(S source); }
TranslatorToJson { public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } return null; } TranslatorToJson(JsonNodeFactory factory, EntityMetadata entityMetadata); JsonDoc translate(S source);  }