PDA

View Full Version : ext gwt 3.0 , JSON with Auto Beans or Overlay? Which one is better approach



hrishirise
31 Jan 2012, 10:28 AM
Hi,
I posted this question in a general discussion before . Posting it in right place .

I am using ext gwt 3.0. I want to make sure which approach is better. Either using AutoBeans or Overlays for JSON handling. Which is better and why.

Colin Alworth
31 Jan 2012, 10:31 PM
Js Overlays and Autobeans are different tools with different purposes. Both are part of the core GWT libraries, and with getter/setter methods exposed, either can be used with GXT 3 (as can any bean-like object).

They can both be used to read from json, after a fashion. AutoBean interfaces are intended to be given a implementation automatically. The AutoBeanCodex (and GXT's JsonReader/JsonWriter) can turn AutoBeans into json and back again. GXT 3's XmlReader/XmlWriter are able to use the properties in the autobeans to copy to/from xml. You can also build implementations of the interfaces given to the AutoBeanFactory, and still get them serialized to xml or json, using the GXT DataWriters mentioned.

AutoBean interfaces are standard Java interfaces, so anything you can do with interfaces, you can do with them, include extending them and making them extend other interfaces (though to implement non-property methods, you need to supply a @Category for the implementation).

JavaScript overlay types let you write code that looks like Java, but is actually JavaScript - object can be casted back and forth in ways that would be illegal in Java. In order to get this to work, all JavaScriptObject (JSO) subclasses must either be final, or their methods must all be final. As a result, you cannot subclass a JSO with an alternate implementation. An additional restriction is that while a JSO can implement an interface, only one JSO can implement that interface (see @SingleJsoImpl), which can restrict the use of that type.

Overlay types can be created from json, using JsonUtils. But their real benefit is that they can also be used to get objects from native javascript, such as JSONP, posting messages between windows, or other JS libraries. Element, Event, and JsDate are a few examples of JSOs that are used to interact with the browser's built in functionality, and the same can be done for any other JavaScript type to use it from Java.

So if all you want is getters and setters to access data read in from a JSON string, either should be acceptable. If you want to use already written DataWriters for reading/writing JSON, JsonReader/JsonWriter and AutoBeans are probably the easiest way forward. If you are reading a JSO from some other JavaScript library, use JSOs and the JsoReader. Much beyond that, it is going to depend on what you are trying to do.