I'm using GWT-RPC to create an application. At certain point the server return a Collection using Collections.unmodifiableList(List l) to the client. The client give an error:

[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'java.util.Collections$UnmodifiableList' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized

So, I need an alternative way to get an only readable Collection, how can I do it? Thanks a lot

my code is the following:

    try {
        LinkedList all=new LinkedList();
        while(res.next()){
            all.add(objectFromCursor(res));
        }
        return Collections.unmodifiableList(all);
    } catch (SQLException e) {
        throw new ExceptionHandler("Error: "+e.getMessage());
    }



private static Film objectFromCursor(ResultSet res) throws SQLException{
    Film film=new Film(res.getString(1));
    film.setRegista(res.getString(2));
    film.setAnnoDiProduzione(res.getInt(3));
    return film;
}
2

There are 2 answers

0
Remigius Stalder On BEST ANSWER

An unmodifiable serializable collection seems to be a contradiction in itself. In order to deserialize an object (I consider "deserializable" to be implied by "serializable"), it must be modifiable.

So simply use a modifiable collection to be passed over GWT-RPC.

0
Fabian On

You could use the ImmutableCollections from guava. https://github.com/google/guava/wiki/ImmutableCollectionsExplained

Guava (link to their Github Page) is a util library from Google for Java but they also made a version for GWT. To use the ImmutableCollections in your project, add guava-gwt to you project and inherit

<inherits name="com.google.common.collect.Collect"/>