users@jersey.java.net

[Jersey] Re: Validating the JSON for put service

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 31 May 2011 08:59:24 +0200

Hi Viraj,

In case, you do not rely on JAXB for JSON de-serialization,
you should be able to use JSR-303 for generic bean validation
(the beauty of that approach is that it should be applicable
in a media type independent way).

See an earlier discussion [1] on the topic to get some hints.

~Jakub

[1]http://jersey.576304.n2.nabble.com/Using-JSR-303-bean-validation-with-Jersey-td2617008.html

On 05/27/2011 09:25 PM, Petr Jurák wrote:
> Hi,
>
> Validate against what? Do you have schema? If so, you should create
> custom ContextResolver<JAXBContext> and in it use your own
> JAXBContext, which should provide Unmarshaller (method
> createUnmarshaller) and Unmarshaller has a method setSchema. This will
> enable validation.
> Hope this helps.
>
> BR, Petr
>
> 2011/5/27 viraj <raj_vid_at_yahoo.com <mailto:raj_vid_at_yahoo.com>>
>
> I am trying to implement *put* service where i will get a JSON as
> request, update the JAXB object and perform update in the
> database. Can you please suggest me how to validate the incoming
> JSON for its structure before performing the update.
>
> @*PUT*
> @Consumes(MediaType.APPLICATION_XML)
> public Response updatePerson(JAXBElement<Person> person) {
> // JSON VALIDATION HERE
> Person p = person.getValue();
> //update to the database
> ...
> }
>
> Thanks
> Viraj
>
>
> ------------------------------------------------------------------------
> View this message in context: Validating the JSON for put service
> <http://jersey.576304.n2.nabble.com/Validating-the-JSON-for-put-service-tp6412109p6412109.html>
> Sent from the Jersey mailing list archive
> <http://jersey.576304.n2.nabble.com/> at Nabble.com.
>
>