Java Generics in GWT-RPC

202 views
Skip to first unread message

Ramon Salla

unread,
Dec 19, 2012, 4:35:14 AM12/19/12
to google-we...@googlegroups.com

We are having a SerializationException error when sending a list of objects using RPC and Java Generics.

I'm creating this widget to show the error:

public class Test<T> {

    ListDataProvider<T> ldp = new ListDataProvider<T>();

    public void setItems(List<T> list){
        for(T t :list){
            ldp.getList().add(t);
        }
    }

    public List<T> getItems(){
        return ldp.getList();

    }

}

This is the code for creating the Test widget and passing a list of POJOs (where ExporterFormKey is the POJO object)

List<ExporterFormKey> list = new ArrayList<ExporterFormKey>();
ExporterFormKey key = new ExporterFormKey();
key.setKey("key1");
list.add(key);

Test<ExporterFormKey> test = new Test<ExporterFormKey>();
test.setItems(list);

At the end the next code throws a SerializationException:

service.sendList(test.getList(), new AsyncCallback...);

While the next one does fine:

service.sendList(list, new AsyncCallback...);


I found that doing the next code also works

List<ExporterFormKey> newList = new ArrayList<ExporterFormKey>(test.getItems());

Ramon Salla

unread,
Dec 19, 2012, 4:44:53 AM12/19/12
to google-we...@googlegroups.com
This change on Test works!! It seems a problem with the ListDataProvider object.

public List<T> getItems(){
    return new ArrayList<T>(ldp.getList());
}

El dimecres 19 de desembre de 2012 10:35:14 UTC+1, Ramon Salla va escriure:

Paul Robinson

unread,
Dec 19, 2012, 4:55:51 AM12/19/12
to google-we...@googlegroups.com
ListDataProvider.getList() returns a list implementation that is not GWT-serializable.

https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication#DevGuideSerializableTypes

If you look at the exception you received, it should tell you (in its own idiosyncratic way) that this class is not serializable.

Paul
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/nIRPhK9-HvQJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Aldin Habibović

unread,
Dec 19, 2012, 5:44:57 AM12/19/12
to google-web-toolkit
check if your model class implements Serializable (or IsSerializable) and check if you have non-construcotra in your model class.
Reply all
Reply to author
Forward
0 new messages