|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
T - The type of the beans to be serialized by the encoder interface.public interface JsonEncoder<T>
An utility interface to allow object serialization to/from json notation.
You can define encoders by extending this interface.
Imagine you have the following java bean class defined as:
public class Person {
private String name;
private int age;
public String getName(){return name;}
public void setName(String name){this.name = name;}
public int getAge(){return age;}
public void setAge(int age){this.age = age;}
}
You can define the following interface to make serialization to / from json notation:
public interface PersonEncoder extends JsonEncoder{}
To use the encoder, just call GWT.create on the given interface, or inject it on your class.
public class MyController {
@Inject
private PersonEncoder encoder;
@Expose
public void myMethod() {
// read the object...
String json = encoder.encode(person);
Person decoded = encoder.decode(json);
}
}
| Method Summary | |
|---|---|
T |
decode(String jsonText)
Encode the given JSON notation string in a object |
String |
encode(T object)
Encode the given object in a JSON notation string |
T |
fromJavaScriptObject(com.google.gwt.core.client.JavaScriptObject object)
Transform the given javascript native object in a java object |
com.google.gwt.core.client.JavaScriptObject |
toJavaScriptObject(T object)
Transform the given object in a javascript native object |
| Method Detail |
|---|
String encode(T object)
object - object to be encoded
com.google.gwt.core.client.JavaScriptObject toJavaScriptObject(T object)
object - object to be encoded
T decode(String jsonText)
jsonText - JSON notation string
T fromJavaScriptObject(com.google.gwt.core.client.JavaScriptObject object)
object - javascript native object to be decoded
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||