//marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
// Set up the JSON StAX implementation
Map<String, String> nstojns = new HashMap<String, String>();
XMLOutputFactory factory = new MappedXMLOutputFactory(nstojns);
XMLStreamWriter xsw = factory.createXMLStreamWriter(os);
marshaller.marshal(obj, xsw);
xsw.close();
} catch (JAXBException e) {
e.printStackTrace();