开发者

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

开发者 https://www.devze.com 2022-12-17 21:33 出处:网络
Let\'s开发者_如何学Go say I have an annotation JSR 303 class like this: class A { @NotNull private String b;

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

精彩评论

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

关注公众号