@Test public void customizeUnmarshaller() throws Exception { byte[] body = "<myRootElement><element>a|||b</element></myRootElement>".getBytes("UTF-8"); MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter(); MockHttpInputMessage inputMessage = new MockHttpInputMessage(body); MyRootElement result = (MyRootElement) myConverter.read(MyRootElement.class, inputMessage); assertEquals("a", result.getElement().getField1()); assertEquals("b", result.getElement().getField2()); }
@Test public void customizeMarshaller() throws Exception { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter(); myConverter.write(new MyRootElement(new MyCustomElement("a", "b")), null, outputMessage); assertXMLEqual( "Invalid result", "<myRootElement><element>a|||b</element></myRootElement>", outputMessage.getBodyAsString(Charset.forName("UTF-8"))); }