[Jersey] Re: Validating the JSON for put service

  • From: Jakub Podlesak <jakub.podlesak@...>
  • To: users@...
  • Subject: [Jersey] Re: Validating the JSON for put service
  • 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@...>
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
Sent from the Jersey mailing list archive at Nabble.com.




[Jersey] Validating the JSON for put service

viraj 05/27/2011

<Possible follow-up(s)>

[Jersey] Validating the JSON for put service

viraj 05/27/2011

[Jersey] Re: Validating the JSON for put service

Petr Jurák 05/27/2011

[Jersey] Re: Validating the JSON for put service

Jakub Podlesak 05/31/2011
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150626.29986a4)
 
 
Close
loading
Please Confirm
Close