@Test public void testTranslateObjectField() throws Exception{ ObjectField objField = new ObjectField("obj"); objField.getFields().addNew(new SimpleField("uid", StringType.TYPE)); EntityMetadata md = fakeEntityMetadata("fakeMetadata", objField); FakeTranslatorToJson<SingleFieldObject<SingleFieldObject<String>>> translator = new FakeTranslatorToJson<SingleFieldObject<SingleFieldObject<String>>>(factory, md) { @Override protected Object getValueFor(Object source, Path path) { if (source instanceof SingleFieldObject<?>) { SingleFieldObject<?> sfo = (SingleFieldObject<?>) source; if ("obj.uid".equalsIgnoreCase(path.toString())) { return ((SingleFieldObject<?>) sfo.value).value; } } throw new RuntimeException("Unexpected"); } }; JsonDoc json = translator.translate(new SingleFieldObject<>(new SingleFieldObject<>("fake value"))); assertNotNull(json); JSONAssert.assertEquals("{\"obj\":{\"uid\":\"fake value\"}}", 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);  }