pascallouisperez / jsonmarshaller

JsonMarshaller is a Java 1.5 library that allows marshalling and unmarshalling of JSON objects to and from entities ("Java classes").
Apache License 2.0
1 stars 0 forks source link

Marshalling strategies instead of options #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, the @Entity annotation has multiple four options (inline, 
subclasses, discriminatorName and discriminator) which must be used in a 
very specific and mutually exclusive way.

The inline annotation specifies that an entity must always be inlined, the 
discriminatorName and subclasses options must be used together to specify 
that an entity is the root of a polymorphic hierarchy and the discriminator 
option specifies a leaf of a polymorphic hierarchy.

In fact, these represents ways to marshall an entity or a marshalling 
strategy.

I propose to deprecate all these options and create instead a

  MarshallingStrategy strategy();

option where MarshallingStrategy is an abstract annotation with three 
concrete subclasses

  @Inline
  @PolymorphicRoot(subclasses = ..., discriminatorName = ...)
  @PolymorphicLeaf(discriminator = ...)

which would define how to marshall a specific entity.

Following the "do the work at compile time" mindset, the library would be 
refactored to have entity descriptors for each strategy.

After this refactoring, we could make the

  @Value(inline = true) EntityClassHere e;

be compiled into the same kind of descriptor as if EntityClassHere were 
annotated with the @Inline strategy. This would speed up the marshalling by 
avoiding unecesseray "if is inlined then/else" checks everywhere.

Original issue reported on code.google.com by pascallo...@gmail.com on 3 Jan 2009 at 2:13