根据AutoValue 文档,用@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