1

I'm stuck with this error:

[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

I've manage to isolate the problem in two Java projects here (just run the project on a from Eclipse as a GWT web application, and press on the button on the page).

What I'm trying to do is create a game with libgdx where the levels can be loaded from an XML file into a POJO. Then I pass the POJO into the engine and it will display the level. I'm using SimpleXML for XML parsing because that library works on both the Android and desktop Java. However I can't use that in the GWT (HTML5) version of the game since the SimpleXML framework uses classes from java.io. (And that isn't allowed because the Java code on the GWT client side is compiled into javascript and that isn't allowed to simply read stuff from any file on the filesystem). So I now load the XML file into a POJO on a GWT server, and try to pass it to the client with the RPC.

The POJO classes are going to be in the Java project that is being used by the Desktop (LWJGL), Android and HTML5 (GWT) version, so the POJO classes cannot implement IsSerializable as the GWT jars can't be in that project. So I followed Glenn's answer in this other stackoverflow topic and made a wrapper class for each POJO that extends the original POJO and implements IsSerializable.

Please help me verify whether this is a bug in GWT or I'm doing it wrong.

Community
  • 1
  • 1
Leejjon
  • 680
  • 2
  • 7
  • 24

1 Answers1

1

IsSerializable is no longer mandatory. The stackoverflow reference you are using is really old. Please go through https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC

The relevant section for you 3. Serializing Java objects

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)

You might have gone off track with your solution. The approach costs you both bandwidth and runtime performance.

appbootup
  • 9,537
  • 3
  • 33
  • 65
  • Thank you for the effort. The funny thing is that removing the wrapper and simply use java.io.Serializable still gives the same error. I've found the reason now, it's the Object.java class I have in my XML structure. Removing it fixed my problem. So now I named it different and it's working fine. Appereantly GWT uses my Object.java instead of java.lang.Object when serializing because it's in the same package. – Leejjon Jan 21 '13 at 20:24