GWT + 序列化

标签 gwt serialization subclass

我很难尝试连载我的类(class)(实际上需要 3-4 小时才能找到解决方案)。我将一个子类添加到现有的可序列化和功能类中,然后收到以下错误消息:

 [ERROR] com.google.gwt.user.client.ui.DelegatingChangeListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.user.client.ui.DelegatingClickListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.user.client.ui.DelegatingFocusListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.user.client.ui.DelegatingKeyboardListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.google.gwt.view.client.ListDataProvider<T>.ListWrapper<> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.client.rpc.ItemRecRpc.LogCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] com.client.rpc.ItemRecRpc.LogCollection has no available instantiable subtypes. (reached via com.client.rpc.ItemRecRpc)
                 [ERROR]    subtype com.client.rpc.ItemRecRpc.LogCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
              [ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument 

我的类(class)看起来像:

public class ItemRecRpc implements Serializable {

    private static final long serialVersionUID = -5828108890651522661L;
        .
        .

        private String rId;
    private LogCollection logColl;//if i comment this, no error message...

    public class LogCollection{ 

        public LogCollection(){

        }
        //public long creationTime = System.currentTimeMillis();
        //public LongVector times = new LongVector();
        //public ArrayList<Object> messages = new ArrayList<Object>();
        //public int nSkipped = 0; 
        //public int nExceptions = 0; 
        //public Exception firstException = null; 
        //public long endGcTime=0;
        public long endTime;
    }
.
.
.
}

当我注释“private LogCollection logColl”行时它没问题,但是当我取消注释时我再次收到错误消息。我尝试使用 static 关键字,如您所见,我注释了每个子类变量,但无能为力......无论如何,如果我创建一个新类:

public class LogCollectionRpc implements Serializable {

    public LogCollectionRpc() {
        //
    }
    public long creationTime = System.currentTimeMillis();
    public LongVector times = new LongVector();
    public ArrayList<Object> messages = new ArrayList<Object>();
    public int nSkipped = 0; // due to reaching the limit
    public int nExceptions = 0; // due to MyAppender-s
    public Exception firstException = null; // due to MyAppender-s
    public long endGcTime = 0;
    public long endTime;

}

然后尝试将其用作我的功能类,没关系......但这件事真的让我很烦恼......

有什么想法吗? Gwt 不支持子类序列化?或者我错过了什么。感谢您的回答。

最好的问候, 彼得

最佳答案

这个错误:

子类型 com.client.rpc.ItemRecRpc.LogCollection 不是默认可实例化的

表示默认情况下它无法创建 LogCollection 的实例。这是真的。因为要创建 LogCollection 实例,首先需要有一个 ItemRecRpc 实例。将 LogCollection 声明为静态类应该有所帮助。

基本上,当您想通过 gwt-rpc 发送一些对象时,所有用作此类对象中字段的类默认情况下都应该是可实例化的。 (例如,没有特殊的技巧来创建它,只是新的和空的构造函数)。您还可以为任何类定义一个自定义字段序列化器,它可以默认实例化。

关于GWT + 序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9211246/

相关文章:

iPhone:覆盖 UIButton buttonWithType 返回子类

ios - 自定义或子类化 CocoaPod 库

java - GWT Bean 验证 (jsr-303) 和 xml 配置

java - 如何在vaadin中设置图像数据源

json - 如何使用 Serde 反序列化带有自定义函数的可选字段?

java - 调度传入 RPC 调用时出现异常

java - 使用类名作为 JSON Jackson 序列化的根键

C# 根据父对象初始化子类

GWT 请求工厂 : How can I get a persistent id from stableId()?

gwt - 将 GWT 可视化的 y 轴格式从毫秒更改为小时 :min:sec