GWT's serializer has limited java.io.Serializable
support, but for security reasons there is a whitelist of types it supports. The documentation I've found, for example this FAQ entry says that any types you want to serialize "must be included in the serialization policy whitelist", and that the list is generated at compile time, but doesn't explain how the compiler decides what goes on the whitelist.
The generated list contains a number of types that are part of the standard library, such as java.lang.String
and java.util.HashMap
. I get an error when trying to serialize java.sql.Date
, which implements the Serializable
interface, but is not on the whitelist. How can I add this type to the list?
There's a workaround: define a new Dummy
class with member fields of all the types that you want to be included in serialization. Then add a method to your RPC interface:
Dummy dummy(Dummy d);
The implementation is just this:
Dummy dummy(Dummy d) { return d; }
And the async interface will have this:
void dummy(Dummy d, AsyncCallback< Dummy> callback);
The GWT compiler will pick this up, and because the Dummy
class references those types, it will include them in the white list.
Example Dummy
class:
public class Dummy implements IsSerializable {
private java.sql.Date d;
}