On Tuesday, April 2, 2013 11:01:39 AM UTC+2, Thomas Broyer wrote:
>
>
>
> On Sunday, March 31, 2013 10:49:07 PM UTC+2, Jeff Schnitzer wrote:
>>
>> When doing custom serialization, is it possible to swap out one class 
>> for another? 
>>
>> This would fix a _lot_ of problems using Objectify's Ref<?> and Key<?> 
>> client-side, including, I think, being able to instantiate Refs and 
>> Keys intelligently. 
>>
>> But I have an immediate problem I'm trying to fix - which is that 
>> Ref<?> is a class hierarchy on the server side, but I'd really like to 
>> simplify this to a single concrete Ref class client-side.  So even 
>> though the sever might return StdRef<?> or NullRef<?>, these should be 
>> converted to a simplified, concrete Ref<?> on the client side. 
>>
>> Is this possible?  It would be even better if I could somehow just 
>> define one custom serializer that handles all Ref subclasses instead 
>> of having to make separate custom serializers for each.
>>
>
> I don't think it's possible, because the type signature is written 
> independently from the custom serializers, so serializing a StdRef on the 
> server-side will put the StdRef type signature in the stream, to be decoded 
> on the client-side.
> You can however just make StdRef and NullRef "super-source" classes that 
> simply inherit from Ref without adding anything, and have their respective 
> custom serializers call the Ref_CustomFieldSerializer methods (at least for 
> the client-side implementation)
>

Revisiting this in response to feedback 
on https://code.google.com/p/google-web-toolkit/issues/detail?id=3303
I got something working in a few minutes without the need for super-source. 
I can't tell whether this is supported though (or whether it might break 
without notice ina future version of GWT).

The thing is that the actual return type from instantiate(), and parameter 
type for deserialize(), are only checked for assignability, and the 
deserialization code (that calls the CustomFieldSerializers) do not check 
the deserialized objects' types; so in LiveRef_CustomFieldSerializer you 
can actually have a "public static Ref 
instantiate(SerializationStreamReader reader) throws 
SerializationException" and "public void 
deserialize(SerializationStreamReader reader, Ref instance)" methods, and 
return a DeadRef instead of a LiveRef.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to