I would like to extend GwtTransient to allow for parametrized serialisation in gwt rpc. The main use case is to send different version of the same object (with more or less data filled in) based on the call being made or on the type of user making the call.
My idea, right now (just an early chain of thoughts), is to add two parameters to the GwtTransient annotation which would be, let's say, "level" and "subLevel". It should be possible to specify several annotations on one field so it would be something like:
public @interface GwtTransient {
Levels[] value();
}
and
public @interface Levels {
String level();
String subLevel();
}
An example us of the annotation would be:
@GwtTransient({@Level(level="one"), @Level(level="two", subLevel="anotherLevel")})
public Object field1;
A "level" parameter needs to be set for the serialisation so that the serialisation process knows which level to use. This could be done for instance by adding a "level" field to the class being serialised and set the it to the corresponding value before returning it in the call (any other/better idea is very welcome ;-)).
Levels would work the following way:
WHEN SERIALISING (and vice versa)
for each field, check annotation
1) no annotation, the field is always serialised
2) an annotation is specified.
2.1) The level used for the call is not included in the list, the field is serialised.
2.2) The level used is included...
2.2.1) no subLevel is specified, the field is NOT serialised
2.2.2) a subLevel is specified, the field is serialised with the corresponding level (cascading of serialisation rules)
It is important to note that there would only be one client object. As with the existing GwtTransient, some fields would not be "filled in".
This is basically the idea. Before I dive into the details, I would like to check with the community if:
1) has this or something equivalent been done before?
2) can you see any major flaw or even showstopper with the idea?
3) do you have any pointers on how to get started to implement this?
Thanks,
Regards,
Thomas