Thanks for your answer!

GWT-RPC does this by convention. The custom serializer must be in the same 
> package as the class it (de)serializes and is named <class 
> name>_CustomFieldSerializer, e.g. ImmutableSet_CustomFieldSerializer.
>

Is it not easier to use the TypeOracle to find CustomFieldSerializer 
JClassType and get all its subtype with JClassType.getSubtypes() ? This way 
you can put your custom serializers anywhere with the name you like. 
 

>
> I wouldn't use an annotation because a guava collection could be used by a 
> large amount of classes so you only want to define the serializer once for 
> a given collection type. To do so you would need some kind of a 
> "configuration" class where you can put annotations once. Or use such a 
> configuration class the google-gin way: 
>
> void configure() {
>   serialize(ImmutableSet.class).with(ImmutableSetJsonSerializer.class).
> }
>

How do you give the configuration class to the generator ? With 
configuration property like below ?
And how does it work ? The generator get the full qualified class name, 
instantiate the class and get the configured serializer from the internal 
map ? Since it's a Class, you then use the TypeOracle to get the 
corresponding JClassType ?
 

>
> If you don't want a configuration class then you could also define a 
> configuration property in your gwt module xml instead. That property could 
> then be filled by users of your library. The property values should point 
> to full qualified class names of custom serializers. google-gin also has an 
> example of this technique because you could define a configuration property 
> and then reference it on the Ginjector like:
>
> @GinModules(value = MyModule.class, properties = { 
> "my.google.gin.extention.property1", "my.google.gin.extention.property2" }
> public interface MyInjector extends Ginjector {}
>
> <define-configuration-property 
> name="my.google.gin.extention.property1" is-multi-valued="true" /> (would 
> go in your library gwt xml)
> <extend-configuration-property name="my.google.gin.extention.property1" 
> value="com.example.ExtentionModule" /> (thats what a library user would 
> need to define in their gwt xml)
>
>  
I didn't know you could do that in Gin, that's nice! (I'm already thinking 
how I could use that to split a big application I'm working on)

For all these configuration methods, is there some built-in method inside 
generators to cache the configuration so you compute it only once ? I 
imagine creating a Map<JClassType, JClassType> (type -> serializer) and 
giving that map to some kind of compilation context.

Thanks again for your answer. 
 

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to