users@jersey.java.net

Re: [Jersey] Schema validation with jersey-spring

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 02 Apr 2010 11:16:02 +0200

On Apr 2, 2010, at 7:39 AM, Mike Key wrote:

> Tatu,
>
> Thanks for the input and response. I think this helps me down a
> path. One question I do have after spending the evening perusing
> the API and some of Paul's old (2008) posts...is there now a
> straight forward way to enable schema validation with JAXB in Jersey?
>

Not currently, you still have to use a ContextResolver<Unmarshaller>
and configure the Unmarshaller to set up the schema. I am not sure of
how to make this easier given the way JAXBContext works and the
necessity for the user to declare types associated with a JAXBContext.


> I may be going the JSR303 route but want to cover all of my options.
>

303 might be a good way to go because schema validation, while in this
case also being specific to XML, can often be too strict especially if
you want to apply some form of Postel's law:

   http://en.wikipedia.org/wiki/Robustness_principle

   "Be conservative in what you do; be liberal in what you accept from
others."

Schematron may be a good option for more flexible XML validation, but
i dunno how to integrate that with JAXB.

I think it is clear that JAXB is showing it's age in terms of being
able to integrate and configure it.

Has anyone used/tried XStream or other XML technologies (that can also
work well with Jackson [*]) that we should consider supporting in
Jersey?

Paul.

[*] Note that i want to make Jackson a better first class citizen of
Jersey as it is clear the JSON JAXB route while initially convenient
does have problems in terms of configuring/tweaking the JSON and what
JSON is actually expected to be produced.


> Thanks again for the response to newbie questions.
>
> Mike
>
> On Apr 1, 2010, at 11:10 PM, Tatu Saloranta wrote:
>
>> On Thu, Apr 1, 2010 at 4:42 PM, Mike Key <mike.key_at_gmail.com> wrote:
>> ...
>>> Also I've noticed a few posts to this mail alias about different
>>> validation means (JSON or XML) that people are considering as part
>>> of JSR 303. So my more important question is...I am 100% new to
>>> JSR303 and am wondering if using this type of validation is
>>> becoming preferred to XML schema validation or is to be used in
>>> conjunction with schema validation? And lastly if it is preferred
>>> to XML
>>
>> I can't say for sure, but I think it is becoming more common, partly
>> because JSR-303 is now mature (which it was not when JAXB and JAX-RS
>> became mature). It is also nice because its use is quite orthogonal
>> to
>> serialization aspects, meaning that it is more widely applicable than
>> data format specific validation.
>>
>>> schema validation...do I use these annotations instead of JAXB
>>> annotations on an interface supporting JSON/XML with Jersey?
>>
>> You would use them as complementary pieces: JAXB annotations to
>> handle
>> data binding, and JSR-303 to indicate constraints for bean
>> properties.
>> Sort of like Schema validation is an optional additional thing for
>> JAX-RS/JAXB. But whereas some JAXB annotations have additional
>> implications for XML Schema generation, there are no such side
>> effects
>> for Bean Validation. Actually, JAXB annotations do not have direct
>> effect on schema validation, but rather they can be used to generate
>> schema, which can then be used for validation, so their effect would
>> be indirect.
>>
>> -+ Tatu +-
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>