Wednesday, December 19, 2012

Re: Java Generics in GWT-RPC

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


On 19/12/12 09:44, Ramon Salla wrote:
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:

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());
--
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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment