I believe everyone who searching this topic in search engine (then landed in my post) already knew what is Gson and when to use it but didn’t know how to use it, so I wouldn’t give any explanation except the topic (excuses for lack in write introduction) :p . Aaa, fine, stay on my page, Gson or Google Json is java library that use for turn your instance of object into JSON serialize String that make it easy to send trough any technology like socket programming and then easy turn it back /deserialize into instance of object by receiver/consumer. By doing that it become more easy in programmatic and developing process. Well then, here we go, first u should download gson.jar, when I write this, I currently use version 1.5 , where to find it? , search engine may help😀 . After that, make a new project and inside of it make a class(es)  / POJO(s) of object that will put inside of producer project and consumer project. This is the way of use model class(es) of object project inside of producer and turn it into serialize String.

List<PddiMember> pddiMembers= new ArrayList<PddiMember>();
Gson gson = new Gson();
String string = gson.toJson(pddiMembers);

And below is the way of use model class(es) of object project inside of consumer, turn back/deserialize the string from producer into class(es) of object.

List<PddiMember> pddiMembers = null;
Gson gson = new Gson();
Type type = new TypeToken<List<PddiMember>>(){}.getType();
try {
    pddiMembers = gson.fromJson(datas, type);
} catch (Exception e) {
    System.out.println(e.getMessage());
}

In my post I using list of class as the model, you also able if you just want to use single class of object. Simple and easy isn’t? It way more easy than send raw of string and parse it by your self and somehow more lightweight than using fully WSDL object.  Hope the post useful.😉

UPDATE : Beside getter and setter, don’t forget to add empty constructor eg : public myClass(){} inside your POJO(s) !

Twitter Subscribe :