users@jersey.java.net

Re: [Jersey] XSD validation during unmarshalling

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 04 Jul 2008 07:20:01 +0200

On Jul 4, 2008, at 1:05 AM, Andrew Cole wrote:

> Hi all
>
> I'm using Jersey 0.7 and have a number of methods that accept
> objects unmarshalled from XML via JAXB bindings. It does not
> appear that the unmarshalling process is validating the XML against
> the schema used to create the JAXB bindings. For instance, I have
> a pattern restriction on a string element that is not being
> respected, and I can leave out elements that have a minOccurs of
> 1. How can I configure the unmarshaller to validate against my
> schema?
>

Currently you need to supply your own JAXBContext that returns a
validating unmarshaller for unmarshalling the JAXB types that require
validation.

See ContextResolver [1].

In this case you would do:

   public class MyContextResolver implements
ContextResolver<JAXBContext> {
     JAXBContext getContext(Class<?> type) { ... }
   }

I plan to make this easier so you can use ContextResolver with an
Unmarshaller/Marshaller thus you don't have to wrap JAXBContext.

Paul.

[1] https://jsr311.dev.java.net/nonav/releases/0.8/javax/ws/rs/ext/
ContextResolver.html