1
根據AutoValue documentation使用註解抽象類@GwtCompatible(serializable = true)並且實現可序列化應該足以讓生成的值類在GWT RPC中可用。然而,隨着下面的類我得到以下錯誤:使用AutoValue GWT序列化例外
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}
我試過各種變種(如只執行常規序列化)沒有成功。這個班有什麼問題?
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();
}
搖籃文件包括
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:https://steffenschaefer.github.io/gwt-gradle-plugin/doc/latest/configuration與碼頭和戰爭插件。但是,我懷疑生成的源不能從GWT訪問,否則在「instance =」之後堆棧跟蹤不能在對象上調用toString。 –
IIUC,此消息顯示在服務器上,並表示序列化策略(由GWT生成)不包含該類,所以可能是GWT沒有看到/有類,但服務器確實是這樣。 –