Yes, I think the question is, are there use cases where a constraint could be applied to several parameters (cross-parameter) and a normal bean or bean property? I guess in most cases a constraint is either one or the other, but there might be exceptions:
@EqualPasswords(appliesToParameters=true)
public void register(String username, String password, String confirmPassword) {
}
@EqualPasswords
public class ResetPasswordRequest {
String password;
String confirmedPassword;
}
@ScriptAssert would be another candidate. Of course you'd need to provide validators for all types to be supported, i.e. Object[], if the constraint shall be applied to a method's parameters.
This would also address the problem that you can't tell whether a constraint applies to a method's return value or its parameters. In fact you could even apply the same constraint to the parameters and the return value:
@ScriptAssert.List({
@ScriptAssert(lang="jexl", script="start < end", appliesToParameters=true),
@ScriptAssert(lang="jexl", script="!_this.conflicts")
})
public Event createEvent(Date start, Date end) {
}
A constraint author could set the default value of appliesToParameters to true, depending on whether the constraint is by its nature a cross-parameter constraint. But users could still set it wrong, causing a UnexpectedTypeException to be thrown.
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
Yes, I think the question is, are there use cases where a constraint could be applied to several parameters (cross-parameter) and a normal bean or bean property? I guess in most cases a constraint is either one or the other, but there might be exceptions:
@ScriptAssert would be another candidate. Of course you'd need to provide validators for all types to be supported, i.e. Object[], if the constraint shall be applied to a method's parameters.
This would also address the problem that you can't tell whether a constraint applies to a method's return value or its parameters. In fact you could even apply the same constraint to the parameters and the return value:
A constraint author could set the default value of appliesToParameters to true, depending on whether the constraint is by its nature a cross-parameter constraint. But users could still set it wrong, causing a UnexpectedTypeException to be thrown.