Annotations binding
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:
- 1.1
- Started by
- Nicolas Leroux
- Completed by
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(@
}
public void index(@
}
public void myMethod(
}
public void myMethod(
}
public void myMethod(
}
}
With the User object as follow:
public class User {
@BindAs(
@BindAs(
public Date creationDate;
@NoBinding(
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(
public Email email;
A format attribute can be specified to @BindAs and @NoBinding allowing to refine your binding:
@BindAs(
This will allows us to do the following
Using the routes file:
GET / application.
Or using the annotation:
@Get(value="/", produces="json")
public void index(@BindAs User user) {
}
with User:
public class User {
@BindAs(
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(
public class myEmail {
}
I think it makes more sense.
The name of the annotations might not be the best one. Anyone with better names?