Converting net.sf.json library to com.google.gson library

Posted on by By admin, in Java | 0

Hello all in this article we are going to learn about JsonObject related. As we know that json object are used widely for getting, storing data and performing simple crud action on data.
In mostly enterprise level application. Due to maintenance of library , or some other reason we have to switch latest librarys, which are maintained by well company.

Now lets learn what are the difference in these librarys:
Storing of data: net.sf.json lib

Converting net.sf.json library to com.google.gson library

Note : the put() method accepts all type value such as String,Int, char, JSONArray, JSONObject, String[] , list etc.

Storing of data: com.google.gson lib

Converting net.sf.json library to com.google.gson library

Note:
1.Here two methods are there add() and addProperty()
add() methods only accepts JsonObject and JsonArray ,
addProperty() methods only stores primative data like string, int, char, boolean.
2.These methods do not store string[], Array list . to store these types we should convert it into either JsonArray , JSONObject or string.
3.JsonArray in both case are using add method.

The difference is it considers value in object form but in gson library it considers as JsonElement.

Fetching Data: net.sf.json

Converting net.sf.json library to com.google.gson library

Note: there are several methods I have covered which are commonly used.

Fetching Data: com.google.gson library

Converting net.sf.json library to com.google.gson library

Note:
1. Here optString, optInt , optBoolean optJSONObject , optJSONArray methods are not present.
2. If these methods requires then we have to implement it manually.

Thank You
Amarnath Mali
Helical IT Solutions

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments