What are the significant diffs between org.json.JSONObject
and
javax.json.JsonObject
?
javax.json.JsonObject
is included in Java EE 7
javax.json.JsonObject
is immutable
org.json.JSONObject
has siginificantly more convenience methods
Most importantly are they interchangeable from client to Webservice?
ie. can I send JSONObject to Webservice and have the Webservice
believe the type is JsonObject (and vice versa)?
Of course this should work. It is not the class instance which gets transferred to the webservice, but the JSON data, which is generated from the class instance. On the other side, the JSON data can be parsed back into any kind of object.
Example:
If you have a simple class named Person:
public class Person {
private String name = "Hans";
private int age = 26;
}
This could be transformed into JSON similar to: {"name":"Hans", "age":25}
The generated JSON string is sent to the webservice.
Now, on the other end of your application, or in any other application, this JSON string can be parsed into any class, if you have an appropriate parser. You don't even need Java to parse it.