开发者

Using JSR 303 is it possible to generate validation.xml from annotations?

Let's开发者_如何学Go say I have an annotation JSR 303 class like this:

class A {
    @NotNull
    private String b;

    @Min(5)
    @Max(10)
    private int num = 3;

    @Pattern(regexp="[0-9]*")
    private String foo = "12345aa";
}

How can I take that class and generate a validation.xml which contains the same constraints as those that are specified by the annotations?


The idea would be to write your own annotation processor. The hard work is to map the annotation to the xml equivalent. There are some examples you could look at on how to write an annotation processor. For example Hibernate Validator uses annotation processing to give developers the ability to verify their constraint placement during development (see ConstraintValidationProcessor). Or have a look at Hibernate's JPA2 Metamodel Generator. AFAIK there is no tool out there yet which does what you want. Btw, why do you want the xml?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜