Hi all,
I'm looking for some input on an idea I got regarding group translation.
When discussing the issue [1] we agreed that the groups to be converted should be specified with a new annotation instead of directly within @Valid. So that's what we have right now:
public class User {
� @Valid
��@ConvertGroup(from = Default.class, to = BasicContact.class)
� private final Contact contact = new Contact();
}
IIRC the primary reason was that this new annotation could be re-used in other places. IMO having a separate annotation is the right way, but WDYT about specifying this annotation within instead of next to @Valid:
��@Valid(conversions=
� � @ConvertGroup(from = Default.class, to = BasicContact.class
� )
� private final Contact contact = new Contact();
This would still allow to reuse the annotation, but avoids situations where @ConvertGroup is given without @Valid. It also makes very clear what's subject of the conversion (which might not be that obvious if the given element hosts some more annotations).
On the down-side the "inner" annotation syntax is not that elegant, although it's actually shorter when specifying multiple conversions:
� @Valid(conversions={
� � @ConvertGroup(from = Default.class, to = BasicContact.class),
� � @ConvertGroup(from = Full.class, to = FullContact.class)
� })
� private final Contact contact = new Contact();
vs.
� @Valid
� @ConvertGroup.List({
� � @ConvertGroup(from = Default.class, to = BasicContact.class),
� � @ConvertGroup(from = Full.class, to = FullContact.class)
� })
� private final Contact contact = new Contact();
This could be further mitigated by naming the attribute "value", although I'm a bit shy of allocating that default attribute.
If we already discussed (and rejected) this particular approach, please ignore this mail, otherwise any feedback is appreciated :)