javaserializationgwtrpcgwt-rpc

SerializationPolicy error when performing RPC from within GWT application


I'm getting the following exception:

com.google.gwt.user.client.rpc.SerializationException: Type 'java.lang.Long' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized

using GWT 2.1 and the built in Jetty server. According to the docs, this type is definitely serializable... How can I include it in the SerializationPolicy?


Solution

  • Needed include a superfluous method in the RPC service that "whitelists" a number of objects. This arises because of the use of generics, GWT is unable to necessarily determine which object I may be serializing to include within some generic.

    I included all of the types that may need to be (un)serialized as members of an object (SerializableWhitelist). I added a method to the RPC servlet object like:

    public SerializableWhitelist junk(SerializableWhitelist l) { return null; }

    It's worth noting that you need to include the whitelist datatypes as both an argument and as the return type, as GWT apparently maintains two separate serialization policies.