So here's my problem: I'm looking for a way to validate ad-hoc (and possibly nested) maps similar to the way one might validate a java bean by using an annotation-based framework. If I had full-blown beans for each of my request objects, then I would annotate them up and validate them using something like Hibernate Validator or OVal.
Where a bean might have annotations like this:
public class MyBean {
@NotEmpty(message = "Name can't be empty!")
@Length(max = 255, message = "Name can't have more than 255 characters!")
private String name;
}
I'm looking for a way to create a validator that might look like this:
Validator validator = new Validator()
.addConstraint("name", new NotEmptyConstraint("Name can't be empty!"))
.addConstraint("name", new LengthConstraint(0, 255, "Name can't have more than 255 characters!"));
The trick here would be that the property values sho开发者_StackOverflow中文版uldn't differentiate between Maps or Objects...much in the way Velocity or Freemarker exressions traverse Maps or beans with the same syntax. There would be bonus points for being able to parameterize the message and substitute the invalid value in.
Does anyone out there know of such a framework? Thanks a million!
精彩评论