How to work around when java.lang.Boolean is in the black list of LegacySerialiaytionPolicy
It took me a while to figure out that java.lang.Boolean is in the blacklist of the LegacySerializationPolicy class. Therefore when my RPC service tries to transfer java.lang.Boolean object, it throws Exception
"Type '*java.lang.Boolean*' 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."
Look at the class com.google.gwt.user.server.rpc.impl.LegacySerialiaytionPolicy
/**
* Many JRE types would appear to be {@link Serializable} on the server.
* However, clients would not see these types as being {@link Serializable}
* due to mismatches between the GWT JRE emulation and the real JRE. As a
* workaround, this blacklist specifies a list of problematic types which
* should be seen as not implementing {@link Serializable} for the purpose
* matching the client's expectations. Note that a type on this list may still
* be serializable via a custom serializer.
*/
private static final Class<?>[] JRE_BLACKLIST = {
java.lang.ArrayStoreException.class, java.lang.AssertionError.class,
java.lang.Boolean.class, java.lang.Byte.class, java.lang.Character.class,
java.lang.Class.class, java.lang.ClassCastException.class,
java.lang.Double.class, java.lang.Error.class, java.lang.Float.class,
java.lang.IllegalArgumentException.class,
java.lang.IllegalStateException.class,
java.lang.IndexOutOfBoundsException.class, java.lang.Integer.class,
java.lang.Long.class, java.lang.NegativeArraySizeException.class,
java.lang.NullPointerException.class, java.lang.Number.class,
java.lang.NumberFormatException.class, java.lang.Short.class,
java.lang.StackTraceElement.class, java.lang.String.class,
java.lang.StringBuffer.class,
java.lang.StringIndexOutOfBoundsException.class,
java.lang.UnsupportedOperationException.class, java.util.ArrayList.class,
java.util.ConcurrentModificationException.class, java.util.Date.class,
java.util.EmptyStackException.class, java.util.EventObject.class,
java.util.HashMap.class, java.util.HashSet.class,
java.util.MissingResourceException.class,
java.util.NoSuchElementException.class, java.util.Stack.class,
java.util.TooManyListenersException.class, java.util.Vector.class};
How to work around ?
Use a custom serializable class instead of java.lang.Boolean
import com.google.gwt.user.client.rpc.IsSerializable; public class SerializedBoolean implements IsSerializable { private boolean value; public static final SerializedBoolean TRUE = new SerializedBoolean(true); public static final SerializedBoolean FALSE = new SerializedBoolean(false); public SerializedBoolean(){ value = false; } public SerializedBoolean(boolean value){ this.value = value; } public boolean isValue() { return value; } public void setValue(boolean value) { this.value = value; } }