2015-07-04 41 views
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

+0

您是否將生成的源代碼(AutoValue_PersonLocalData的源代碼)包含到GWT編譯器的類路徑中?也許你可以展示更多的'build.gradle'。 –

+0

我在這裏使用GWT插件gradle:https://steffenschaefer.github.io/gwt-gradle-plugin/doc/latest/configuration與碼頭和戰爭插件。但是,我懷疑生成的源不能從GWT訪問,否則在「instance =」之後堆棧跟蹤不能在對象上調用toString。 –

+2

IIUC,此消息顯示在服務器上,並表示序列化策略(由GWT生成)不包含該類,所以可能是GWT沒有看到/有類,但服務器確實是這樣。 –

回答

0

GWT和註釋處理是不舒服同牀。關鍵似乎是將註釋處理分成前提步驟。例如,我剛剛通過遵循組主題BoilerplateGeneration maven configuration的方式使用了Maven的這個工作:在編譯步驟中禁用註釋處理,而是將其作爲生成源的一部分運行,因此GWT可以在運行時將它們視爲源文件。過去,我已將註釋類編譯到JAR(包括生成的源代碼)中,並在包含該JAR的單獨項目上運行GWT編譯。不幸的是,我沒有Gradle特定的建議。