We get a SerializationException error when sending a list of objects using RPC and Java Generics.
I create this widget to show an 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 a Test widget and passing a POJO list (where ExporterFormKey is a 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 of the following code, a SerializationException is thrown:
service.sendList(test.getList(), new AsyncCallback...);
While the following does well:
service.sendList(list, new AsyncCallback...);
----- Edit ----
I found that executing the following code also works
List<ExporterFormKey> newList = new ArrayList<ExporterFormKey>(); newList.add(test.getItems().get(0)); service.sendList(newList , new AsyncCallback...);
Or it also works
List<ExporterFormKey> newList = new ArrayList<ExporterFormKey>(test.getItems());
I also found this change in test work!
public List<T> getItems(){ return new ArrayList<T>(ldp.getList()); }
ramon_salla
source share