Annotations binding

Registered by Nicolas Leroux

This blue print discusses the new annotations binding of the 1.1 serie.

Blueprint information

Status:
Started
Approver:
None
Priority:
Undefined
Drafter:
Nicolas Leroux
Direction:
Needs approval
Assignee:
Nicolas Leroux
Definition:
Discussion
Series goal:
None
Implementation:
Slow progress
Milestone target:
milestone icon 1.1
Started by
Nicolas Leroux

Sprints

Whiteboard

Implement a new superset of annotations that allows easy binding. After a long discussion, Guillaume and I come up with the following:

@BindAs
@NoBiding

@BindAs has 4 attributes: value, lang, binder
@NoBinding has 2 attributes: value

@BindAs can be used as method parameter or on field / setter / getter of an object.
@NoBinding can be used on field / setter / getter of an object.

Here are snippets of code where they could be used:

public class myController extends controller {

   public void index(@BindAs("yyyy-MM-dd") Date date) {
   }

   public void index(@BindAs("yyyy-MM-dd",lang="fr,en") Date date) {
   }

   public void myMethod(@BindAs("€####,##") Float currency) {
   }

   public void myMethod(@BindAs("€####,##",lang="fr,en") Float currency) {
   }

   public void myMethod(@BindAs("secureForm") User user) {
   }

}

With the User object as follow:

public class User {

    @BindAs("yyyy-MM-dd")
    @BindAs("yyyy-dd-MM", lang="us")
    public Date creationDate;

    @NoBinding("secureForm")
    public Boolean isAdmin;

}

Question: do we want to have @BindAs linked to a form (like "secureForm") and not only the lang?

The binder attribute of the @BindAs annotations allows you to specify your own implementation:

@BindAs(binder=MyEmailBinder.class)
public Email email;

A format attribute can be specified to @BindAs and @NoBinding allowing to refine your binding:

@BindAs(binder=MyXMLBinder.class,format="xml") or @NoBinding(format="xml")

This will allows us to do the following

Using the routes file:

GET / application.index(format:'json')

Or using the annotation:

@Get(value="/", produces="json")
public void index(@BindAs User user) {
}

with User:

public class User {

   @BindAs(value="MM-dd-yyyy", format="json")
   public Date createdDate;

}

However, as the format attribute needs more use case and will not be implemented at first. It will be an enhancement for later.

I am also wondering if the binding attribute should not be specified at the class level to avoid repetition ie:

@BindAs(binder=MyEmailBinder.class)
public class myEmail {
}

I think it makes more sense.

The name of the annotations might not be the best one. Anyone with better names?

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.