Saturday, September 25, 2010

GWT Custom Serialization

I am having a slight problem with a framework I am making. Here is an
example class:
public class Example implements IsSerializable
{
private final int a;

private final int b;

public Example(int a,int b)
{
this.a=a;
this.b=b;
}

// getters ...
}

A very simple class. However, there is no way to serialize it using
GWT. Although the simple work-around is to remove the "final"
attribute from the fields, that does not "jive" with, what I consider,
solid programming. The "final" attribute means that no where, in any
instance of the class or any instance of a descendant of this class,
will the values of "a" and "b" be modified in any way (exception:
using Java reflection). More than the optimization that many JVMs will
do, there is also a type of safety - the programmer cannot
accidentally put the reference on the left hand side of an assignment
operator.

The GWT compiler will emit a warning that the final fields will not be
serialized. Using the "_CustomFieldSerializer" is also impossible
because the deserialize method takes an instance of the class you are
deserializing as a parameter - instead it should have the return value
as an instance of the class.

So, other than removing the final attribute, has anyone had any luck
side-stepping this issue? Anyone know of any bug reports or
enhancement requests for this (I have searched, but have come up
empty).

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment