try {
// Set up the JSON StAX implementation
Map<String, String> nstojns = new HashMap<String, String>();
XMLOutputFactory factory = new MappedXMLOutputFactory(nstojns);
XMLStreamWriter xsw = factory.createXMLStreamWriter(os);
xsw.writeStartDocument();
if (obj instanceof XmlObject) {
XmlObject xObj = (XmlObject)obj;
XMLBeanStreamSerializer ser = new XMLBeanStreamSerializer();