MailMarshaller extends ObjectMapper implements Marshaller, Unmarshaller { @Override public void marshal(Object graph, Result result) { if (type.equalsIgnoreCase(MessageType.JSON.name())) { if (result instanceof StringResult) { StringWriter writer = new StringWriter(); ((StringResult) result).setWriter(writer); try { writer().writeValue(writer, graph); } catch (IOException e) { throw new CitrusRuntimeException("Failed to write mail object graph to result", e); } } } else if (type.equalsIgnoreCase(MessageType.XML.name())) { jaxbDelegate.marshal(graph, result); } else { throw new CitrusRuntimeException("Unsupported mail marshaller type: " + type); } } MailMarshaller(); @Override boolean supports(Class<?> clazz); @Override Object unmarshal(Source source); @Override void marshal(Object graph, Result result); String getType(); void setType(String type);  }
@Test public void testMarshal() throws Exception { MailRequest mailRequest = new MailRequest(); mailRequest.setFrom("foo@mail.com"); mailRequest.setTo("bar@mail.com,copy@mail.com"); mailRequest.setSubject("Testmail"); BodyPart mailBodyPart = new BodyPart(); mailBodyPart.setContentType("text/plain"); mailBodyPart.setContent("Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua."); mailRequest.setBody(mailBodyPart); StringResult mailRequestResult = new StringResult(); mailMarshaller.marshal(mailRequest, mailRequestResult); MailRequest result = (MailRequest) mailMarshaller.unmarshal(new StringSource(mailRequestResult.toString())); Assert.assertEquals(result.getFrom(), "foo@mail.com"); Assert.assertEquals(result.getTo(), "bar@mail.com,copy@mail.com"); }