Si verifica un errore SerializationException quando si invia un elenco di oggetti che utilizzano RPC e Java Generics.GWT e Generics
Sto creando questo widget per mostrare l'errore:
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();
}
}
Questo è il codice per creare il widget di test e il superamento di un elenco di POJO (dove ExporterFormKey è l'oggetto POJO)
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);
alla fine il codice successivo tiri un SerializationException:
service.sendList(test.getList(), new AsyncCallback...);
Mentre il prossimo uno fa bene:
service.sendList(list, new AsyncCallback...);
----- Modifica ----
Ho trovato che facendo il codice seguente funziona anche
List<ExporterFormKey> newList = new ArrayList<ExporterFormKey>();
newList.add(test.getItems().get(0));
service.sendList(newList , new AsyncCallback...);
O questo funziona anche
List<ExporterFormKey> newList = new ArrayList<ExporterFormKey>(test.getItems());
Ho anche trovato questa modifica su Test funziona!
public List<T> getItems(){
return new ArrayList<T>(ldp.getList());
}
Potrebbe essere necessario eseguire il cast di test.getList() per digitare Elenco o Dichiarare test con . –
SSR
Probabilmente il tuo ListDataProvider() non restituisce un ArrayList ma un'altra implementazione di List (ad esempio un elenco restituito Collections.unmodifiableList() o un tipo derivato da AbstractList. Potresti pubblicare la SerializationException completa e il log del server? la serializzazione non funziona e quale è la classe offendente. –
izaera