Stefano Bossi
Stefano Bossi

Reputation: 1437

JsonObject vs JSONObject

I am a bit confused about Json Class in java libraries. I could find these 3 at least and all seems Oracle Json Libraries

Why so many Oracle json class?

Upvotes: 1

Views: 2207

Answers (2)

Stephen C
Stephen C

Reputation: 718906

I could find these 3 at least and all seems Oracle Json Libraries

Actually, there are many more than that; see the list at https://www.json.org/json-en.html. Many are not Oracle classes. Indeed org.json.JSONObject is not an Oracle class.

Why so many Oracle json class?

History. It took a long time for Oracle to include JSON support in the official Java libraries. And by the time that they did, various other people / organizations had produced their own offerings, and developed their own followings.

(The reason the Oracle have two JSON implementations is that their design goals are significantly different.)

Which one is the recommended one and why?

There is no single recommendation. It very much depends on what your application requires in terms of JSON support. Do you want something light-weight? Do you need to fit in with an existing framework (e.g. Java EE or Java ME)? Do you need POJO "bindings"? Streaming parsers?

Upvotes: 6

maio290
maio290

Reputation: 6732

You are mixing up a lot of things here.

javax.json is part of the JSON-B and JSON-P Java EE API - used for JSON processing and data binding. And used in context of an application server (WildFly / Tomcat / ...)

whereas com.oracle.json refers to Java ME ("Micro Edition").

and org.json is just another parser, like GSON.

You wouldn't use com.oracle.json outside of a Java ME environment, but whether you use javax.json, org.json, GSON, Jackson, ... is up to your personal taste and requirements. But mostly, the application server already contains a JSON parser - for Wildfly, this was Jackson until JSON-B/P arrived rather late to the parsing party.

Upvotes: 3

Related Questions