JAXBUtils { public static String marshal(Object obj) throws JAXBException { return marshal(obj, obj.getClass()); }  static String marshal(Object obj); @SuppressWarnings("unchecked") static String marshalWithoutRootElement(T obj); static T unmarshalFromXml(Class<T> clazz, String xml);  }
@Test public void testMarshal() throws JAXBException, SAXException, IOException { final JAXBTestElement obj = new JAXBTestElement(); obj.setField1(FIELD1_VALUE); obj.setField2(FIELD2_VALUE); final String xml = JAXBUtils.marshal(obj); assertNotNull(xml); assertTrue(StringUtils.hasText(xml)); assertXMLEqual(XML, xml); }
@Test public void testMarshal_JAXBException() throws JAXBException, SAXException, IOException { thrown.expect(JAXBException.class); JAXBUtils.marshal(new Object()); }