I seem to have found the right answer to my question
I realized that converting bean to json and json to bean in GWT is not a trivial task. Well-known libraries will not work because GWT will require their full source code, and this source code should only use Java classes that emulate GWT. In addition, you cannot use reflection in GWT. Very strict requirements!
I found the only existing solution called gwt-jsonizer . It uses its own Generator class and requires a satellite interface for each jsonable bean. Unfortunately, it does not work without fixing the latest version of GWT and does not update for a long time.
So, I personally decided it was cheaper and faster to make my khow beans how to convert myself to and from json. Like this:
public class SmartBean { private String name; public String getName() { return name; } public void setName(String value) { name = value; } public JSONObject toJson() { JSONObject result = new JSONObject(); result.put("name", new JSONString(this.name)); return result; } public void fromJson(JSONObject value) { this.name = value.get("name").isString().stringValue(); } }
JSONxxxx are GWT built-in classes that provide low level json support.
amartynov Mar 26 '09 at 8:05 2009-03-26 08:05
source share