@Test public void testTranslateSimpleArrayField() throws Exception { EntityMetadata md = fakeEntityMetadata("fakeMetadata", new ArrayField("array", new SimpleArrayElement(StringType.TYPE))); FakeTranslatorToJson<SingleFieldObject<String[]>> translator = new FakeTranslatorToJson<SingleFieldObject<String[]>>(factory, md) { @Override protected List<? extends Object> getSimpleArrayValues(Object o, SimpleArrayElement simpleArrayElement) { return Arrays.asList((String[]) o); } @Override protected Object getValueFor(Object source, Path path) { if (source instanceof SingleFieldObject) { return ((SingleFieldObject<?>) source).value; } throw new RuntimeException("Unexpected"); } }; JsonDoc json = translator.translate(new SingleFieldObject<>(new String[]{"hello","world"})); assertNotNull(json); JSONAssert.assertEquals("{\"array\":[\"hello\",\"world\"]}", 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);  }