JAXBUtils { @SuppressWarnings("unchecked") public static <T> String marshalWithoutRootElement(T obj) throws JAXBException { final JAXBElement<T> wrappedJaxbElement = new JAXBElement<T>(new QName( obj.getClass().getSimpleName()), (Class<T>) obj.getClass(), obj); return marshal(wrappedJaxbElement, 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 testMarshalWithoutRootElement() throws JAXBException, SAXException, IOException { final JAXBTestElementWithoutRoot obj = new JAXBTestElementWithoutRoot(); obj.setField1(FIELD1_VALUE); obj.setField2(FIELD2_VALUE); final String xml = JAXBUtils.marshalWithoutRootElement(obj); assertNotNull(xml); assertTrue(StringUtils.hasText(xml)); assertXMLEqual(XML_WITHOUT_ROOT, xml); }