Search code examples
javaxmlregexweb-servicesjax-ws

JAX-WS @Pattern annotation for regex validation


I am using xjc to generate java classes from my XML schema for a JAX-WS webservice.

In my schema I am specifying a type for a comma separated list of integers:

<xs:simpleType name="IntegerList">
    <xs:restriction base="xs:string">
        <xs:pattern value="(\d+,)*\d+" />
    </xs:restriction>
</xs:simpleType>

When elements of this type are converted to java classes by xjc, they become String objects (as they should) , however the regex validation is lost.

I read somewhere about the @Pattern annoation which should be used for regex's.

Why isn't xjc using this annotation, and how can I fix it to perform regex validation in the Java too?

Thank you for helping


Solution

  • I have not attempted to use pattern restrictions with xjc myself. Based on the following post, I am led to believe that xjc does not natively create the @Pattern restriction, but an enterprising soul has posted a customization on java.net that is advertised to manage creation of @Pattern (among others). [http://www.java.net/forum/topic/glassfish/metro-and-jaxb/jaxb-plugin-generate-bean-validation-annotations-jsr-303][1]

    @parvez is correct that the java.net link has been retired and did provide a relevant current link in comment to functionality.