【问题标题】:GWT Serialization exception with AutoValue带有 AutoValue 的 GWT 序列化异常
【发布时间】:2015-07-04 13:28:28
【问题描述】:

根据AutoValue documentation@GwtCompatible(serializable = true) 注释抽象类并实现可序列化应该足以使生成的值类在GWT RPC 中可用。然而,对于下面的课程,我收到以下错误:

Caused by: com.google.gwt.user.client.rpc.SerializationException: 
Type 'com.my.package.client.types.AutoValue_PersonLocalData' 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.: instance = PersonLocalData{title=Dr., givenName=Philip, familyName=Mortimer}

我尝试了各种变体(比如只实现常规的 Serializable)但没有成功。上课有什么问题?

import java.io.Serializable;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.GwtCompatible;
import com.google.gwt.user.client.rpc.IsSerializable;

@AutoValue
@GwtCompatible(serializable = true)
public abstract class PersonLocalData
        implements IsSerializable, Serializable {

    public static final long serialVersionUID = 1L;

    public static PersonLocalData create(
            String title,
            String givenName,
            String familyName) {
        return new AutoValue_PersonLocalData(
                title, givenName, familyName);
    }

    public abstract String getTitle();
    public abstract String getGivenName();
    public abstract String getFamilyName();
}

Gradle 文件包括

compile 'com.google.guava:guava:18.0'
compile 'com.google.guava:guava-gwt:18.0'
compile 'com.google.auto.value:auto-value:1.1'

GWT 版本:2.6.0

【问题讨论】:

  • 您是否将生成的源代码(AutoValue_PersonLocalData 的源代码)包含在 GWT 编译器的类路径中?也许你可以展示更多你的build.gradle
  • 我正在使用 GWT 的 gradle 插件,这里提供:steffenschaefer.github.io/gwt-gradle-plugin/doc/latest/… 和 jetty 和 war 插件。但是,我怀疑生成的源不能从 GWT 访问,否则堆栈跟踪无法在“instance =”之后调用对象上的 toString。
  • IIUC,此消息显示在服务器上,并表示序列化策略(由 GWT 生成)不包括该类,因此可能是 GWT 没有看到/拥有该类但服务器会。
  • 我创建了几种类型,似乎问题来自具有嵌套自动值类型的自动值类型。
  • 好吧,它应该可以工作:github.com/google/auto/pull/257

标签: java gwt serialization auto-value


【解决方案1】:

GWT 和注释处理是不舒服的伙伴。关键似乎是将注释处理分离为先决条件步骤。例如,我刚刚通过遵循 Groups 主题BoilerplateGeneration maven configuration 使用 Maven:在编译步骤中禁用注释处理,而是将其作为 generate-sources 的一部分运行,因此 GWT 可以在运行时将它们视为源文件。过去,我将带注释的类编译成 JAR(包括生成的源代码)并在包含该 JAR 的单独项目上运行 GWT 编译。不幸的是,我没有针对 Gradle 的建议。

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2012-04-18
    • 2012-03-21
    • 1970-01-01
    • 2012-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多