users@jersey.java.net

Re: [Jersey] Jersey JSON validations.

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 16 Aug 2010 15:59:52 +0200

Hi Girish,

I am not aware of any validation support with JSONObject. The area of
JSON schema is still work in progress AFAIK.

There is some ongoing work with Jackson:

   http://www.cowtowncoder.com/blog/archives/2010/05/entry_398.html

Otherwise you either have to roll your own, perhaps using a Jersey
resource filter and some annotation defining the validator. Or you
might be able to reuse Jersey's JSON/JAXB support with JAXB
validation. But, since this is pure JSON you might want to look a
little more closely at Jackson.

Paul.


On Aug 16, 2010, at 8:25 AM, Girish Amarsi Rathod wrote:

> Hi,
> We are using Jersey to implement the RESTfull service/resource
> for our client server application . In case of AJAX
> communications , this service/resource is talking to UI using the
> JSON ( media type - application/json) . As indicated in the sample
> code below, we are using the
> “org.codehaus.jettison.json.JSONObject” to send the data to UI and
> receive it back as JSON. This JSONObject has a inbuild support to
> hold the key value pairs for JSON.
>
> @POST
> @Path("/updateTokens")
> @Consumes("application/json")
> public JSONObject anyMethod(JSONObject jSONObject) {
>
> .
> .
>
> }
>
>
> This is working perfectly. But now we want to implement the
> validation. This validation should ideally be binding time
> validation , in the sense , if the ‘required’ field is not present
> in the incoming (to server side) JSON , it should not call this
> method, the request should get redirected to the UI with the error
> message.
>
> So, given the setup and the requirement, can you let me know how can
> I do this , is there any in-build support for this type of validation.
> It would be really great if you can assist me in this, I’m not able
> to find much help online.
>
> Thanks,
> Girish
>