AutoValue的GWT序列化异常

时间:2015-07-04 13:28:28

标签: java gwt serialization auto-value

根据AutoValue documentation使用 @GwtCompatible(serializable = true)注释抽象类,并且实现serializable应该足以使生成的值类在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

1 个答案:

答案 0 :(得分:0)

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