Tuesday, April 17th, 2007
GWT-Jsonizer: JSON/JavaBeans translator
<p>Andrés Testi has developed a JSON/JavaBean translator for the Google Web Toolkit named GWT Jsonizer, which simplifies theGWT 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
-
-
/**
-
* 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
-
-
// 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){
-
}
-
Related Content:











Leave a comment