@Test public void testSerialization() throws RenderableException, IOException { Data data = new Data(); data.name = "wisdom"; data.age = 2; RenderableObject object = new RenderableObject(data); serializer.serialize(object); String result = IOUtils.toString(object.render(null, null)); assertThat(result) .contains("<Data") .contains("</Data>") .contains("<name>wisdom</name>") .contains("<age>2</age>"); }
@Override public void serialize(Renderable<?> renderable) { try { String serialized = xml.xmlMapper().writeValueAsString(renderable.content()); if (serialized == null || serialized.length() == 1) { LOGGER.error("Cannot serialize result - cannot create a JSON Node from the response content"); renderable.setSerializedForm(""); } else { renderable.setSerializedForm(serialized); } } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
XMLSerializer implements ContentSerializer { @Override public void serialize(Renderable<?> renderable) { try { String serialized = xml.xmlMapper().writeValueAsString(renderable.content()); if (serialized == null || serialized.length() == 1) { LOGGER.error("Cannot serialize result - cannot create a JSON Node from the response content"); renderable.setSerializedForm(""); } else { renderable.setSerializedForm(serialized); } } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }
XMLSerializer implements ContentSerializer { @Override public void serialize(Renderable<?> renderable) { try { String serialized = xml.xmlMapper().writeValueAsString(renderable.content()); if (serialized == null || serialized.length() == 1) { LOGGER.error("Cannot serialize result - cannot create a JSON Node from the response content"); renderable.setSerializedForm(""); } else { renderable.setSerializedForm(serialized); } } catch (JsonProcessingException e) { throw new RuntimeException(e); } }  }
XMLSerializer implements ContentSerializer { @Override public void serialize(Renderable<?> renderable) { try { String serialized = xml.xmlMapper().writeValueAsString(renderable.content()); if (serialized == null || serialized.length() == 1) { LOGGER.error("Cannot serialize result - cannot create a JSON Node from the response content"); renderable.setSerializedForm(""); } else { renderable.setSerializedForm(serialized); } } catch (JsonProcessingException e) { throw new RuntimeException(e); } }  @Override String getContentType(); @Override void serialize(Renderable<?> renderable); }
XMLSerializer implements ContentSerializer { @Override public void serialize(Renderable<?> renderable) { try { String serialized = xml.xmlMapper().writeValueAsString(renderable.content()); if (serialized == null || serialized.length() == 1) { LOGGER.error("Cannot serialize result - cannot create a JSON Node from the response content"); renderable.setSerializedForm(""); } else { renderable.setSerializedForm(serialized); } } catch (JsonProcessingException e) { throw new RuntimeException(e); } }  @Override String getContentType(); @Override void serialize(Renderable<?> renderable);  }