GWT and Android. Enum serialization error

I have a perfectly working GWT application. Now I'm trying to use gwt-syncproxy to create an Android client that can simply reuse server-side code.

So far, everything has worked perfectly. The only problem I can find is when I run RPC for a method that expects an enumeration as a parameter.

Renaming looks something like this:

 import java.io.Serializable; import com.google.gwt.user.client.rpc.IsSerializable; public enum ReferenceTable implements IsSerializable, Serializable { basetable, othertable; ReferenceTable(){} } 

The error message I get is:

 com.google.gwt.user.client.rcp.IncompatibleRemoteServiceException: Invalid type signature for package.ReferenceTable 

which suggests that this is a serialization issue.

I tried using different combinations of IsSerializable and Serializable and always deleted the project before deployment. Both the GWT application and the Android application use the same code for the data types used for communication.

Does anyone have any ideas how to solve this? If nothing works, I could refrain from using enums, but I would prefer to use them. Moreover, everything works for the very connection between the server and the GWT client.


BTW: Server side error:

 Caused by: com.google.gwt.user.client.rpc.SerializationException: Invalid type signature for some.package.ReferenceTable at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.validateTypeVersions(ServerSerializationStreamReader.java:1116) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.deserialize(ServerSerializationStreamReader.java:610) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.readObject(ServerSerializationStreamReader.java:567) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader$ValueReader$8.readValue(ServerSerializationStreamReader.java:140) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.deserializeValue(ServerSerializationStreamReader.java:425) at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:312) ... 24 more 

EDIT

I created an example GWT application and an example application for Android, so people can really try the code:

To deploy the application, simply modify the build.properties file and then run build.xml as an ant script. In the MainActivity the Android application, change the URL to point to the GWT application.

+6
source share
2 answers

I cannot verify your problem as described (using the provided src, it works in my dev environment using a JB emulator), although I saw your indicated error during the development of the Android library. I found that many of the problems of "serialization" in GWT are usually something small, such as non-serializable member types, missing interfaces, default constructors, etc. Since it looks like you've already accessed these features, please check the following:

The version of GWT used in the web application on your computer. The Android OS version is being tested (emulator or device) and which device if necessary.

Although I do not expect this to be a problem, the Android library was compiled using GWT 2.5.0 src, so it is possible (not yet verified theory) that if the server works with GWT other than 2.5.0, RPC serialization occurs because of this.

This also explains why the desktop client works, but not in the Android library. The syncproxy library for desktop clients compiles against GWT, not GWT, so you link your version of GWT at compile time. The Android library was compiled directly with the GWT src code for version 2.5.0 with several user overrides to reduce the size of the library that will be used and managed in the Dalvik environment.

At the same time, if it is possible for your project, try using GWT 2.5.0, clean / recompile and take a picture. If not, then on my to-do list, to get the library to 2.5.1, but I still did not have time.

Disclaimer: I created the appropriate Android library as a contributor to the gwt-syncproxy project. I cannot say that I understand all the inputs and outputs of GWT or the internal components of syncproxy, but at least enough to get a working library model. I am open to suggestions for improving the library or any ideas about where in the internal details we should look to solve this if there is any gwt guru there ...

+2
source

Remove the IsSerializable interface declaration from:

 public enum ReferenceTable implements IsSerializable, Serializable 

To:

 public enum ReferenceTable implements Serializable 

Simply, if your application is purely GWT, you should use the IsSerializable interface, but in this case you want to use the same code with the Android application, you should only use the Serializable interface.

0
source

Source: https://habr.com/ru/post/954772/


All Articles