开发者

Getting JSON as string to a model object with Jersey

开发者 https://www.devze.com 2023-02-10 03:05 出处:网络
We\'re currently using Jersey 1.5.1 + Spring for handling JSON requests, and the request structure looks something like this:

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 info;
}

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 o开发者_如何转开发ne for this particular case?


If you don't want to parse JSON into java, you should simply use a JSON parser directly on the input.

0

精彩评论

暂无评论...
验证码 换一张
取 消