import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.mapped.Configuration;
import org.codehaus.jettison.mapped.MappedNamespaceConvention;
import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
import javax.xml.stream.XMLStreamException;
import java.io.StringWriter;
public class JettisonExample {
public static void main(String[] args) throws JSONException, XMLStreamException {
JSONObject jsonObject = new JSONObject(json);
String name = jsonObject.getString("name");
int age = jsonObject.getInt("age");
JSONObject jsonObj = new JSONObject(person, new Configuration());
StringWriter writer = new StringWriter();
MappedXMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(new MappedNamespaceConvention(new Configuration()), writer);
jsonObj.write(xmlStreamWriter);
String jsonStr = writer.toString();
System.out.println(jsonStr);
}
private static class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
// getters and setters
}
}