GWT-Jsonizer: JSON/JavaBeans translator
Written by on April 17th, 2007 in Ajax News.
Andrés Testi has developed a JSON/JavaBean translator for the Google Web Toolkit named GWT Jsonizer, which simplifies the
GWT interaction with non-java backends.
The Jsonizer interface, has only two methods: ‘asJavaObject’ and ‘asString’. As possibly you can infer, the ‘asJavaObject’ method unjsonizes JSON values, and the ‘asString’ method, performs the opposite action.
Example
JAVA:
-
-
/**
-
* If you wants to jsonize it, you need to implement an extension of
-
* Jsonizer interface suffixed with the ‘Jsonizer’ keyword.
-
*/
-
interface PersonJsonizer extends Jsonizer{}
-
-
// A JSON String with Person properties
-
String json = ‘{’name’:'Andres’,'age’:28}’;
-
-
// Create the Person Jsonizer
-
PersonJsonizer jsonizer = (PersonJsonizer)GWT.create(PersonJsonizer.class);
-
try{
-
// Translate the JSON String to a Person bean
-
Person p = (Person)JsonizerParser.parse(jsonizer, json);
-
}catch(JsonizerException e){
-
Window.alert(’JSON Translation Error!’);
-
}
-
Source: Ajaxian
Original Article: http://ajaxian.com/archives/gwt-jsonizer-jsonjavabeans-translator