import javax.xml.bind.JAXBContext; import org.codehaus.jettison.json.JSONObject; JAXBContext jc = JAXBContext.newInstance(MyClass.class); JSONObject jsonObject = new JSONObject(); import org.codehaus.jettison.mapped.MappedXMLStreamWriter; MappedXMLStreamWriter writer = new MappedXMLStreamWriter(jsonObject); jc.createMarshaller().marshal(obj, writer); String jsonString = jsonObject.toString(); import org.codehaus.jettison.json.JSONObject; JSONObject json = new JSONObject(jsonString); MyClass obj = (MyClass) jc.createUnmarshaller().unmarshal(json); import org.codehaus.jettison.mapped.Configuration; import org.codehaus.jettison.mapped.MappedNamespaceConvention; import org.codehaus.jettison.mapped.MappedXMLStreamWriter; Configuration config = new Configuration(); config.setSupressAtAttributes(true); MappedNamespaceConvention con = new MappedNamespaceConvention(config); MappedXMLStreamWriter writer = new MappedXMLStreamWriter(con, jsonObject);


上一篇:
下一篇:
切换中文