|
Playing the devil's advocate here: What's the big advantage of @ValidateReference, wouldn't you still have to annotate each single element? One would at least need a class-level annotation which allows to propagate all constraints from the source to target type:
@ApplyConstraintsFrom(User.class)
public class UserBean { ... }
One general shortcoming is the dependency that this approach creates between the different models, something which may not be desirable (if even possible, taking multi-module projects into account, where e.g. a view layer may not be able to "see" a domain/persistence layer).
As an alternative an API for "constraint copying" would be possible, e.g. something like the following:
ConstraintCopier cc = ...;
cc.copyConstraints()
.type(CustomerEntity.class)
.mapTo(CustomerView.class)
.type(OrderEntity.class)
.mapTo(OrderView.class)
.property( "itemCode" )
.ignore()
.property( "size" )
.mapTo( "orderedSize" )
.ignoreConstraints( Length.class );
|