Skip to main content

Defining length restriction in Java Bean

1 reply [Last post]
Joined: 2010-03-31

Hello all,

I find myself in quite a predicament in a project using JAX-WS to expose our services as SOAP endpoints.

We have defined a series of services with the corresponding Beans (all programatically), and let JAX-WS dinamically generate the WSDL and XSD based on the annotations in the beans.

The problem is that we would like to be able to validate the length of some of the fields.

Is there any way that I can pass this information to JAX-WS (through annotatations or otherwise), so that this ends up in the XSD?

My first approach was try to find some annotation that would let me define the length, just the same way one can define a
to limit a field to a set of values, or even
@XmlElement(name="myelement", required = false)

Is there any way I can complement this so that the lengths of the fields are validated in the SOAP request?

Thank you in advance!


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-02-02

I've been searching for this exact same functionality. In general though JAX-WS is rather lax in it's enforcement of the XSD unless you use the @SchemaValidated annotation. Still more to your exact question, there is no length annotations that I'm aware of. I believe one of the work arounds is to throw an exception from the setter when the length is too short. Luckily any exception you throw from the webservice becomes a soap fault. So you can either do the validation yourself (blah) or use something like JSR 303 Bean Validation ( which has the @Size annotation.

Good luck.