The best you can use in the client to handle json are Overlays. http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsOverlay.html
On Tue, Nov 9, 2010 at 7:17 PM, Kashif <kashifshaikh...@gmail.com> wrote: > Hi everyone, > > I have a class that I want to share both with client and server code, > in my particular case it's the JSONObject. > > It has different implementations on client > (com.google.gwt.json.client.JSONObject) and server > (org.json.JSONObject), but same interface. > > So I have a DTO class like this shared between client and server, so I > can use JSON to pass objects around and wrap them in JSONObjects for > easy API access: > > class Person { > > String firstName; > String lastName; > > public JSONObject toJson() > { > // code to convert firstname + lastname to JSON > } > > public fromJSON (JSONObject x) > { > // code to read from JSONObject and set firstName and lastName > } > } > > There is no way for me to tell GWT to use > com.google.gwt.json.client.JSONObject when compiling this class on > client, and likewise use org.json.JSONObject on server. I would have > to resort to Java String. > > Now I could do the following, but I would have to re-write the toJson/ > fromJson methods for each implementation - not acceptable to me! > > class PersonBase > { > String firstname; > String lastname; > } > > class Person_Client extends PersonBase > { > public fromJSON (om.google.gwt.json.client.JSONObject x) > { > // code to read from JSONObject and set firstName and lastName > } > > public com.google.gwt.json.client.JSONObject toJson() > { > // code to convert firstname + lastname to JSON > } > } > > class Person_Server extends PersonBase > { > public fromJSON (org.json.JSONObject x) > { > // code to read from JSONObject and set firstName and lastName > } > > public org.json.JSONObject toJson() > { > // code to convert firstname + lastname to JSON > } > } > > There must be an easier way! > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to google-web-tool...@googlegroups.com. > To unsubscribe from this group, send email to > google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > > -- Guit: Elegant, beautiful, modular and *production ready* gwt applications. http://code.google.com/p/guit/ -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.