GWT Serialization with CustomFieldSerializer fails because of SerializationPolicy

68 views
Skip to first unread message

Daniel Kurka

unread,
Apr 14, 2009, 10:36:53 AM4/14/09
to google-web-toolkit
For data transport we use a simple java class containing a Map<String, Object> This map is transient and we serialize it with a custom field serializer. This works fine for most situations.


For every service gwt has a list of classes which can be Serialized (whitelist). If my understanding is right this list is generated by the compiler at compile time by analizing the members of a class.

But we can have classes (which ARE serializable) inside our transient map, but gwt will not serialize this classes because of the SerializationPolicy (these classes could not be found by the compiler at compile time).

Is there any way to extend the white list of SerializationPolicy.java ?

If I add all classes as private members to my class the members are found and the class can be serialized, but this is anoying and we cant do this for all classes (we dynamically decide which classes we need to transfer)

Anyone got any expierence with that?

Maybe open an issue about this?



fvisticot

unread,
Apr 14, 2009, 3:57:14 PM4/14/09
to Google Web Toolkit
I have the same issue with an RPC service witch return a
List<Object>...
The compiler does not find the type of elements that could be included
in the list...
As a workarround i'm obliged to create dummy methods using the classes
that could be included in the list...

I would like to know how to extend the SerializationPolicy
(whiteList...) ?? perhaps can we use annotations like
@gwt.typeArgs

Salvador Diaz

unread,
Apr 15, 2009, 6:24:21 AM4/15/09
to Google Web Toolkit
> perhaps can we use annotations like @gwt.typeArgs

Those are deprecated, you should really avoid using them

> > a simple java class containing a Map<String,Object>

Can't you just use a Map<String, Serializable> ? If the map is going
to be travelling through RPCs you really shouldn't be putting objects
that don't implement Serializable into it.

Cheers,

Salvador

Daniel Kurka

unread,
Apr 15, 2009, 3:30:46 PM4/15/09
to Google-We...@googlegroups.com
The problem is that the compiler will create the code for al objects in the classpath that implement serialiazable (which are more ore less 10000+).

This results in enormous compile time and huge javascript...

absolutely not doable

any more suggestions?

2009/4/15 Salvador Diaz <diaz.s...@gmail.com>

fvisticot

unread,
Apr 15, 2009, 5:29:36 PM4/15/09
to Google Web Toolkit
I have exactly the same issue with post:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/1b7e3851b943b130/2aa2077f4e6c90e1#2aa2077f4e6c90e1

I have used the Serializable solution but my code/library contains a
lot of Serializable classes as well... I really would like to avoid
this solution...
Is it not possible:
1. to implement the SerializationPolicy and add the class that are
Serializable.
2. define annotations in the RPC service with allowed Serializable
objects.

Fred

On Apr 15, 9:30 pm, Daniel Kurka <kurka.dan...@googlemail.com> wrote:
> The problem is that the compiler will create the code for al objects in the
> classpath that implement serialiazable (which are more ore less 10000+).
> This results in enormous compile time and huge javascript...
>
> absolutely not doable
>
> any more suggestions?
>
> 2009/4/15 Salvador Diaz <diaz.salva...@gmail.com>
>
>
>
>
>
> > > perhaps can we use annotations like @gwt.typeArgs
>
> > Those are deprecated, you should really avoid using them
>
> > > >  a simple java class containing a Map<String,Object>
>
> > Can't you just use a Map<String, Serializable> ? If the map is going
> > to be travelling through RPCs you really shouldn't be putting objects
> > that don't implement Serializable into it.
>
> > Cheers,
>
> > Salvador
>
> > > > For every service gwt has a list of classes which can be Serialized
> > > > (whitelist). If my understanding is right this list is generated by the
> > > > compiler at compile time by analizing the members of a class.
>
> > > > But we can have classes (which ARE serializable) inside our transient
> > map,
> > > > but gwt will not serialize this classes because of the
> > SerializationPolicy
> > > > (these classes could not be found by the compiler at compile time).
>
> > > > Is there any way to extend the white list of SerializationPolicy.java ?
>
> > > > If I add all classes as private members to my class the members are
> > found
> > > > and the class can be serialized, but this is anoying and we cant do
> > this for
> > > > all classes (we dynamically decide which classes we need to transfer)
>
> > > > Anyone got any expierence with that?
>
> > > > Maybe open an issue about this?- Hide quoted text -
>
> - Show quoted text -

Salvador Diaz

unread,
Apr 16, 2009, 6:10:27 AM4/16/09
to Google Web Toolkit
> any more suggestions?

Create a marker interface for the objects that you want to go through
RPCs and type your Map with it:

public interface DTO extends Serializable{
}

...

The you declare your Map as:
Map<String, DTO>

Would that work ?

Vitali Lovich

unread,
Apr 16, 2009, 6:13:53 AM4/16/09
to Google-We...@googlegroups.com
Using IsSerializable instead of Serializable should also cut down on the number of objects (although of course you have to modify your classes if you marked them as Serializable only).

kurka....@googlemail.com

unread,
Apr 16, 2009, 4:14:19 PM4/16/09
to Google Web Toolkit
I added my concerns to this issue in the gwt issue tracker:

http://code.google.com/p/google-web-toolkit/issues/detail?id=3521

Salvador Diaz

unread,
Apr 17, 2009, 3:18:26 AM4/17/09
to Google Web Toolkit
Frankly I don't see how that issue could be accepted, the fact that
you have to mark all your serializable objects as Serializable or
IsSerializable has been there from the beginning. It's related to the
way the compiler has to know at compile time what objects are allowed
to travel through RPCs and how they should be serialized. You simply
cannot expect it to magically detect the types that will be added to
your <String, Object> map.

Vitali Lovich

unread,
Apr 17, 2009, 3:45:01 AM4/17/09
to Google-We...@googlegroups.com
Hasn't been accepted - just opened.  Anyone can open issues against GWT.

That being said, I think there could be room for improvement.  For instance, if you specify a serializable interface or serializable abstract class, you should be allowed to enumerate all the various types that can possibly go across the wire in an annotation so as to provide more contextual information that the compiler simply doesn't otherwise have access to at compile time.

@Transfers({A.class, B.class, C.class, D.class})
Serializable foo(Serializable[] x);

etc. which limits the compiler to only look at A, B, C, & D when it comes across trying to compile this RPC function.

This would solve a lot of issues & make the expressiveness much more powerful.

Daniel Kurka

unread,
Apr 17, 2009, 4:20:58 PM4/17/09
to Google-We...@googlegroups.com
this is exactly what i was thinking.

we need a way to specify the classes that are okay to serialiaze with the service

2009/4/17 Vitali Lovich <vlo...@gmail.com>

fvisticot

unread,
Apr 18, 2009, 4:35:21 PM4/18/09
to Google Web Toolkit
+1, a way to specify Object to serialize would be fine !!!

On Apr 17, 10:20 pm, Daniel Kurka <kurka.dan...@googlemail.com> wrote:
> this is exactly what i was thinking.
> we need a way to specify the classes that are okay to serialiaze with the
> service
>
> 2009/4/17 Vitali Lovich <vlov...@gmail.com>
>
>
>
> > Hasn't been accepted - just opened.  Anyone can open issues against GWT.
>
> > That being said, I think there could be room for improvement.  For
> > instance, if you specify a serializable interface or serializable abstract
> > class, you should be allowed to enumerate all the various types that can
> > possibly go across the wire in an annotation so as to provide more
> > contextual information that the compiler simply doesn't otherwise have
> > access to at compile time.
>
> > @Transfers({A.class, B.class, C.class, D.class})
> > Serializable foo(Serializable[] x);
>
> > etc. which limits the compiler to only look at A, B, C, & D when it comes
> > across trying to compile this RPC function.
>
> > This would solve a lot of issues & make the expressiveness much more
> > powerful.
>

Raphaël POCHET

unread,
Apr 24, 2009, 5:35:17 AM4/24/09
to Google Web Toolkit
I agree with that, i'm using a generic DTO too with a Map<String,
Object> because i don't want to bother to create an
IServiceInterfaceAsync for every RPC method i need. So telling in an
annotation to GWT which objects are likely to travel over http would
be nice.

However if we could provide something more flexible than annotation
config, it would be nice. My RPC service is part of my framework, and
i don't want to have to modify the API to mark the serializable
implemenation DTOs.

On 18 avr, 22:35, fvisticot <fvisti...@gmail.com> wrote:
> +1, a way to specify Object to serialize would be fine !!!
>
> On Apr 17, 10:20 pm, Daniel Kurka <kurka.dan...@googlemail.com> wrote:
>
>
>
> > this is exactly what i was thinking.
> > we need a way to specify the classes that are okay to serialiaze with the
> > service
>
> > 2009/4/17 Vitali Lovich <vlov...@gmail.com>
>
> > > Hasn't been accepted - just opened.  Anyone can open issues against GWT.
>
> > > That being said, I think there could be room for improvement.  For
> > > instance, if you specify a serializable interface or serializable abstract
> > > class, you should be allowed to enumerate all the various types that can
> > > possibly go across the wire in anannotationso as to provide more
Reply all
Reply to author
Forward
0 new messages