Search code examples
gwtenumsdeserializationgwt-rpc

GWT: List of enums throws "could not deserialize response"


I have a simple POJO which has some attributes, one of them being an enum. This worked fine but when I changed the enum attribute to a List of enums GWT gives me a serialization exception "could not deserialize the response".

This works:

public class Report implements Serializable, Comparable<Report> {

    private static final long serialVersionUID = 1L;

    private long id;
    //some more attributes, all serialize fine
    private ReportCategory category; // the enumeration 

    public ReportSVO(){
    }
        //.. generated getters and setters
}

When I changed the private ReportCategory category; to private List<ReportCategory> categories; I got the (de)serialization exception.

Out of a hunch, I changed the enum to an inner class: (public enum ReportCategory{...} to public class ReportCategory{ private Name categoryName; public enum Name{...}}) and like magic, it works. This problem leads me to two questions:

  1. Is this a GWT bug? Or am I missing something?
  2. Is there a nicer way to solve this problem?

The enum itself should not be a problem as it was working before (and enums are serializable by default). Also, when I forgot a no-args constructor on other GWT classes or had a non-serializable attribute the serialization exception message was like this: "com.google.gwt.user.client.rpc.SerializationException: Type '...' was not included in the set of types which can be serialized by this SerializationPolicy.."

I am using GWT 2.4


Solution

  • As it turns out, the cause for my problem was am mismatch between the POJO-class (Report) on the server side and the compiled-to-Javascript version of the class. This was because I changed the class and republished it to the server but forgot to re-compile client-side code...

    So on the server-side the attribute was a list and on the client-side it was still an enumeration and the deserialization then of course failed.

    All in all quite a face-palm, but I hope this thread help someone in the future.