java - How do I serialize a complex Class in GWT? -
i want serialize following class autobeans.
public class getresults<t extends dto> implements result { list<t> results; protected getresults() { } public getresults(list<t> results) { this.results = results; } public list<t> getresults() { return results; } public void setresults(list<t> results) { this.results = results; } }
here tried failed:
public class autobeanserializer { private final autobeanfactory factory; public autobeanserializer(autobeanfactory factory) { this.factory = factory; } public string <t> encodedata(t data) { autobean<t> autobean = autobeanutils.getautobean(data); return autobeancodex.encode(autobean); } public <t> t decodedata(class<t> datatype, string json) { autobean<t> bean = autobeancodex.decode(factory, datatype, json); return bean.as(); } }
the above code not work line
public string encodedata(t data) {
has these errors:
- t cannot resolved type - type string not generic; cannot parameterized arguments <t>
how serialize above class abstract types in gwt?
you can use lib: https://code.google.com/p/gwt-streamer/
it job if implement streamable in classes.
here example documentation:
public class person implements streamable { // fields, visibility doesn't matter private string name; private int age; private person() {} // default no-args constructor required public person( string name, int age ) { this.name = name; this.age = age; } // getters, setters optional... }
server , client use same api serialization.
person person = new person( "anton", 33 ); string buffer = streamer.get().tostring( person ); //... person = (person) streamer.get().fromstring( buffer ); //... person personcopy = streamer.get().deepcopy( person );
Comments
Post a Comment