T - The type of the beans to be serialized by the encoder interface.public interface JsonEncoder<T>
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);
}
}
| Modifier and Type | Method and Description |
|---|---|
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
|
String encode(T object)
object - object to be encodedcom.google.gwt.core.client.JavaScriptObject toJavaScriptObject(T object)
object - object to be encodedT decode(String jsonText)
jsonText - JSON notation stringT fromJavaScriptObject(com.google.gwt.core.client.JavaScriptObject object)
object - javascript native object to be decodedCopyright © 2015. All rights reserved.