How to define javax.validation.constraints.Size.List in my binding file using jaxb annotate and annox plugins?

1.3k Views Asked by At

I want to use JSR 303 Bean validation on my classes. My problem is that these classes are generated from schema. I am using the jaxb annotate plugin on my bindings file and was able to define simple validation annotations like @NotNull. My problem comes when I have to define multiple annotations of same type for different groups. javax.validation offers a solution for this using annotations like @Size.List{@Size...). How can I use jaxb-annotate and annox plugin to define annotations like those.

1

There are 1 best solutions below

0
On

You can define nested annotations with Annox, it's no problem. In your case it will be something like:

In *.xjb file:

<annox:annotate>
  <annox:annotate annox:class="javax.validation.constraints.Size$List">
    <annox:annotate annox:field="value">
       <annox:annotate annox:class="javax.validation.constraints.Size" .../>
    </annox:annotate>
  </annox:annotate>
</annox:annotate>

In schema:

<annox:annotate>
  <c:Size$List xmlns:c="http://annox.dev.java.net/javax.validation.constraints">
    <c:value>
      <c:Size ... />
    </c:value>
  </c:Size$List>
</annox:annotate>

I haven't tested it, so the syntax may be a bit different.

See the Annox user guide an the Annotate plugin docs.