Originally all my dtos used in my rpcs implemented IsSerializable in
an old project at work.
I thought id try the latest build 1163 ( i think thats it) against it.
Im not sure why but i searched + replaced all the implements
IsSerializable with java.io.Serializable. I then recompiled to
javascript and tried my app ( didnt bother trying in no server mode ).
I got a few strange errors in the deserialization process on the
client - the rpc worked. It was obvious that the serialized string
wasnt valid and didnt match what should be there. On top of that the
string was too short. After more checking on the server i tracked down
the problem.
ServerSerializationStreamWriter was asking the oracle if that object
should be serialized and it returned false because the class
implemented java.io.Serializable and not Gwt's IsSerializable.
Taking a look at the oracle which is asked if a class should have its
fields serialized its obvious what the bug is.
com.google.gwt.user.server.rpc.impl.ServerSerializableTypeOracleImpl
public boolean isSerializable(Class instanceType) {
if (instanceType.isArray()) {
return isSerializable(instanceType.getComponentType());
}
if (instanceType.isPrimitive()) {
return true;
}
if (IsSerializable.class.isAssignableFrom(instanceType)) {
return true;
}
/// FIX START
if (java.io.Serializable.class.isAssignableFrom(instanceType)) {
return true;
}
/// FIX END
return hasCustomFieldSerializer(instanceType) != null;
}
Nowhere does the code test and throw an exception if an object is not serializable. WIth that in mind it is also possible to make the serialization process a bit safer and faster with the following changes.
public void writeObject(Object instance) throws SerializationException {
if (instance == null) {
// write a null string
writeString(null);
return;
}
SUGGESTION
why not ask the oracle here if the instance is serializable and throw an exception if the object isnt.
private void serializeClass(Object instance, Class instanceClass){
...blha blah..
if (superClass != null && serializableTypeOracle.isSerializable(superClass)) {
serializeImpl(instance, superClass);
}
}
SUGGESTION:
Why is the if above testing if the instance is super class is serializable ? If the sub-class impls serializable ( GWT or java.io) does it make sense to also serialize the super's fields.
Why not simply the if statement to only test superclass != null.
--
Miguel