gpt4 book ai didi

java - AutoValue 的 GWT 序列化异常

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:30 29 4
gpt4 key购买 nike

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

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}

我尝试了各种变体(例如仅实现常规的可序列化),但没有成功。类(class)出了什么问题?

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

最佳答案

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

关于java - AutoValue 的 GWT 序列化异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31221158/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com