users@jersey.java.net

[Jersey] Get JSON as plain string

From: Arseni Grigorjev <arsenikum_at_gmail.com>
Date: Fri, 11 Feb 2011 10:57:50 +0200

Hi,

I have problems figuring out how to dig out a plain JSON string from a
request.

We're currently using Jersey 1.5.1 + Spring for handling JSON requests,
and the request structure looks something like this:

    {
       "id": 34324242,
       "foo": "bar",
       "info": {
          "infofield1": "some value",
          "infofield2": "some other value",
          "infodetails": {
            "details1": "aaaa",
            "details2": "bbbb"
          }
       }
    }

The Java class to which this request would map (ideally) looks like this:

@XmlRootElement
public class FooBarRequest {

     public Integer id;

     public String foo;

     public String infoJson;
}

The idea is, that we want to get "info" as plain json string (not parsed
to a any java object structure) to store it directly to DB as a BLOB.
This doesn't seem to work out-of-a-box for Jersey 1.5.1, we are
currently trying to upgrade to Jersey version 1.6, but maybe you have
some tips on how to do that?

Maybe there is a ready XmlAdapter, which would perform something like
this for us?
If not, does anyone know, how to write one for this particular case?

Best regards,
Arseni.