users@jersey.java.net

Jersey JSON validations.

From: Girish Amarsi Rathod <arathod_at_smartequip.com>
Date: Sun, 15 Aug 2010 23:25:45 -0700

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