Org.json.JSONObject vs. javax.json.JsonObject?

What are the significant differences between:

org.json.JSONObject and javax.json.JsonObject?

Most importantly, are they interchangeable with a client on Webservice? i.e. can I send a JSONObject to the Webservice and make sure that the Webservice is a JsonObject (and vice versa)?

(JSONObject found in json-20080701.jar ACRA)

(JsonObject found in C: \ glassfish4 \ glassfish \ modules \ javax.json.jar)

+5
source share
1 answer

What are the significant differences between org.json.JSONObject and javax.json.JsonObject ?

  • javax.json.JsonObject included in Java EE 7
  • javax.json.JsonObject is immutable
  • org.json.JSONObject has significantly more convenient methods

Most importantly, are they interchangeable with a client on Webservice? i.e. can I send a JSONObject to the Webservice and have a web service what type is JsonObject (and vice versa)?

Of course, this should work. This is not an instance of the class that is passed to the webservice, but JSON data that is generated from the instance of the class. On the other hand, JSON data can be parsed back to any object.

Example:

If you have a simple class called Person:

 public class Person { private String name = "Hans"; private int age = 26; } 

This can be converted to JSON, similar to: {"name":"Hans", "age":25}

The generated JSON string is sent to the webservice.

Now, at the other end of your application, or in any other application, this JSON string can be parsed in any class if you have the appropriate parser. You don't even need Java to parse it.

+4
source

Source: https://habr.com/ru/post/1214035/


All Articles