2013-01-20 61 views
1

我堅持了這個錯誤:FieldSerializer編譯錯誤GWT序列

[DEBUG] [testgwt] - Rebinding org.stofkat.testgwt.client.GetTestsService 
[INFO] [testgwt] - Module testgwt has been loaded 
[ERROR] [testgwt] - Errors in 'generated://CB9089E742875E64C1F5E08E3E60A8B5  /org/stofkat/testgwt/shared/TestsWrapper_FieldSerializer.java' 
[ERROR] [testgwt] - Line 9: The type TestsWrapper_FieldSerializer must implement the inherited abstract method TypeHandler.serial(SerializationStreamWriter, Object) 
[ERROR] [testgwt] - Line 9: The type TestsWrapper_FieldSerializer must implement the inherited abstract method TypeHandler.deserial(SerializationStreamReader, Object) 
[ERROR] [testgwt] - Line 36: Type mismatch: cannot convert from TestsWrapper to Object 
[ERROR] [testgwt] - Line 40: Cannot cast from Object to TestsWrapper 
[ERROR] [testgwt] - Line 44: Cannot cast from Object to TestsWrapper 
[INFO] [testgwt] - See snapshot: C:\Users\Leejjon\AppData\Local\Temp\org.stofkat.testgwt.shared.TestsWrapper_FieldSerializer4210265464022362123.java 

我設法找出問題的兩個Java項目here(只是一個從Eclipse中運行該項目作爲GWT網應用程序,然後按下頁面上的按鈕)。

我想要做的是用libgdx創建一個遊戲,其中的級別可以從XML文件加載到POJO中。然後我將POJO傳遞到引擎中,它將顯示關卡。我使用SimpleXML進行XML解析,因爲這個庫可以在Android和桌面Java上運行。但是,我不能在遊戲的GWT(HTML5)版本中使用它,因爲SimpleXML框架使用了來自java.io的類。 (這是不允許的,因爲GWT客戶端的Java代碼被編譯爲javascript,並且不允許簡單地從文件系統的任何文件中讀取內容)。所以我現在將XML文件加載到GWT服務器上的POJO中,並嘗試通過RPC將它傳遞給客戶端。

POJO類將在桌面(LWJGL),Android和HTML5(GWT)版本中使用的Java項目中,所以POJO類無法實現IsSerializable,因爲GWT罐不能處於該項目。所以我遵循Glenn的回答this other stackoverflow topic,併爲每個擴展原始POJO並實現IsSerializable的POJO創建一個包裝類。

請幫我驗證這是GWT中的錯誤還是我做錯了。

回答

1

IsSerializable不再是強制性的。你使用的stackoverflow參考是非常古老的。請通過https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC

的相關章節您3.序列化的Java對象

A type is serializable and can be used in a service interface if one of the following is true: 

All primitive types (int, char, boolean, etc.) and their wrapper objects are serializable by default. 
An array of serializable types is serializable by extension. 
A class is serializable if it meets these three requirements: 
It implements either Java Serializable or GWT IsSerializable interface, either directly, or because it derives from a superclass that does. 
Its non-final, non-transient instance fields are themselves serializable, and 
It has a default (zero argument) constructor with any access modifier (e.g. private Foo(){} will work) 

你可能出現了偏離軌道與您的解決方案。該方法使您的帶寬和運行時性能都降低。

+0

謝謝你的努力。有趣的是,刪除包裝,並簡單地使用java.io.Serializable仍然給出了相同的錯誤。我現在找到了原因,它是我的XML結構中的Object.java類。刪除它解決了我的問題。所以現在我把它命名爲不同的,它工作正常。當序列化時,GWT使用我的Object.java而不是java.lang.Object,因爲它在同一個包中。 – Leejjon