2013-01-20 62 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