Imagine that you want to send any Serializable class to the client side of your GWT application using DTO:
public class MyDTO implements Serializable { public Serializable value; }
In addition, everything that is used as a value will be checked if it is installed before it is set. GWT really throws a couple warnings to the dev console:
DEBUG: com.example.app.shared.MyDTO. DEBUG: Analyzing the fields of type 'com.example.app.shared.MyDTO' that qualify for serialization. DEBUG: private java.io.Serializable value. DEBUG: java.io.Serializable. DEBUG: Verifying instantiability. DEBUG: java.util.ArrayList<? extends java.lang.Object>. WARN: Checking all subtypes of Object which qualify for serialization. DEBUG: com.google.gwt.validation.client.impl.PathImpl. DEBUG: Verifying instantiability. DEBUG: com.google.gwt.validation.client.impl.PathImpl. DEBUG: Analyzing the fields of type 'com.google.gwt.validation.client.impl.PathImpl' that qualify for serialization. WARN: Field 'private final java.util.List<javax.validation.Path.Node> nodes' will not be serialized because it is final.
But! Unfortunately, this causes the GWT to throw a Serialization RPC exception when it is sent to the client side:
com.google.gwt.user.client.rpc.SerializationException: Type 'com.example.app.shared.MyDTO' 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.: instance = com.example.app.shared.MyDTO@577f52ed at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619) at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126) at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44) ...
Bottomline: How do you prevent GWT from fitting to Serializable subtypes?
EDIT:
I ended up creating a subclass for each class I needed.
source share