Java 我能';不在GWT集合中使用。不可修改列表(列表l)仅使我的列表可读,因为它是';t可串行化,替代方法?

Java 我能';不在GWT集合中使用。不可修改列表(列表l)仅使我的列表可读,因为它是';t可串行化,替代方法?,java,list,collections,gwt-rpc,unmodifiable,Java,List,Collections,Gwt Rpc,Unmodifiable,我正在使用GWT-RPC创建一个应用程序。在某一点上,服务器使用Collections.unmodifiableList(列表l)向客户端返回一个集合。客户端提供了一个错误: [WARN] Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: Type 'java.util.Collections$UnmodifiableList' was not

我正在使用GWT-RPC创建一个应用程序。在某一点上,服务器使用Collections.unmodifiableList(列表l)向客户端返回一个集合。客户端提供了一个错误:

[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
所以,我需要另一种方法来获得一个唯一可读的集合,我该怎么做?非常感谢

我的代码如下:

    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;
}

不可修改的可序列化集合本身似乎是一个矛盾。为了使对象反序列化(我认为“可序列化”)是“可序列化的”,它必须是可修改的。
因此,只需使用一个可修改的集合就可以通过GWT-RPC传递。

您可以使用来自guava的ImmutableCollections。

Guava()是googleforjava的一个util库,但他们也为GWT制作了一个版本。要在项目中使用ImmutableCollections,请将guava gwt添加到项目并继承

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

为什么需要通过GWT-RPC传递不可修改的列表?一旦列表到达客户端,它将从服务器实例中分离,即客户端修改不会传播到服务器(除非您在另一个GWT-RPC请求中将其发送回来)。