JaxbUtils { public static <T> String marshalToString(T object) throws JAXBException { Marshaller marshaller = buildMarshaller(object); StringWriter stringWriter = new StringWriter(); marshaller.marshal(object, buildXMLFilterImpl(stringWriter)); return stringWriter.toString(); } private  JaxbUtils(); static Marshaller buildMarshaller(T object); static String marshalToString(T object); static Document marshalToDocument(T object); static Unmarshaller buildUnmarshaller(Class... clazz); static T unmarshal(String message, Class... clazz); static T unmarshal(Node message, Class... clazz); static boolean isObjectContainNull(Object object); static boolean isGetValueNull(Object object, Method method); static List<Document> objectsToDocument(List<Object> objects); static Node buildPayloadObject(T object);  }
@Test public void marshalToString() throws Exception { RpcReplyV10 rpcReplyV10 = new RpcReplyV10(); rpcReplyV10.setMessageId(MESSAGE_ID); String result = JaxbUtils.marshalToString(rpcReplyV10); assertTrue(result.contains("rpc-reply")); assertTrue(result.contains(MESSAGE_ID)); RpcReplyV10 rpcUnmarshal = JaxbUtils.unmarshal(result, RpcReplyV10.class); assertEquals(rpcReplyV10.getMessageId(), rpcUnmarshal.getMessageId()); }