GWT Custom Serialization

154 views
Skip to first unread message

melody

unread,
Jan 19, 2007, 9:27:08 PM1/19/07
to Google Web Toolkit
I have seen this
http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/3e728f1be219756f/07bc38ac4914fb56?lnk=gst&q=GWT+Custom+Serialization&rnum=1#07bc38ac4914fb56

message from the forums but I could not reply to it because it is too
old. However I had a copule of questions.

1. Where is the documentation for Custom Serialization that Miguel
referred to in the post?
2. Do I have an option to implement just the method I need e.g. for my
use case, I just want to customize the instantiation of the object to
initialize some static variable that depends on the values of certain
instance variables?
3. Can I call default serialization methods where I dont wish to write
code for serializing/deserializing every field/member in the object.
For instance in Java, if you have an object you wish to customize
serialize (if only slightly), you implement the method readObject as
follows

private void readObject(java.io.ObjectInputStream stream) throws
IOException, ClassNotFoundException {
//Set some transient of static member varialble to value you
wish
MyClass.mystaticVariable = 1;
//then call the default serializer to do the rest instead of
having to write the code for all member varialbles
stream.defaultReadObject();
}


Thanks Miquel or Anyone who wishes to weigh in.


Melody

Dan Morrill

unread,
Jan 22, 2007, 11:09:43 AM1/22/07
to Google-We...@googlegroups.com

Hi, melody!

Some quick answers for you:
1. The internals of the current RPC serialization mechanism are not really documented anywhere.  Note that we don't generally expect users to be reimplementing this, so it's not considered a "user-visible" feature and thus not a high priority to document.  So, you'll have to check the JavaDocs and the source code.

2 & 3.  Note that GWT's RPC mechanism does not use java.io.Serializable. Instead, GWT uses a custom IsSerializable interface, precisely to make it clear that it is not standard Java serialization.  That is, the semantics of Serializable that you are used to do not apply.  Among other things, this means that you don't have readObject() and writeObject().

In general, we never really intended anyone to treat the GWT serialization mechanism as an interface to reimplement.  To support JSON, GWT provides a JSON library, so the RPC implementation is strictly intended to make it easy to communicate with Java Servlets.  So, as Miguel said, it's theoretically possible to do, but we don't necessarily recommend it.  At the very least, it would be a pretty significant amount of work.

Besides all that, we have work underway to redesign the serialization mechanism.  While that doesn't mean that the old system will go away, it does mean you might be implementing a backend for a protocol that is deprecated.

What are your goals? Is there some way you can meet them without reimplementing the RPC serialization?  Also, if you're interested in this topic, feel free to join in the discussion over on the Google-Web-Toolkit-Contributors list:  http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/069174e689e0d7c8/194bc25e8a089a4e#194bc25e8a089a4e

- Dan Morrill
Reply all
Reply to author
Forward
0 new messages