Hi Arseni,
My guess is that is quite tricky to do with JAXB because it uses a SAX
parser, and thus the XML or JSON is already parsed and JAXB does not
have access to the underlying characters.
I don't think an XmlAdapter will do it, because it does not have
access to the underlying characters and it also does not know if the
source was XML or JSON.
For your case you might want to see if Jackson can do it. It may
require that you write your own message body reader/writer for the
type in question using the lower level JSON parsing if Jackson cannot
do it at the binding level.
Paul.
On Feb 11, 2011, at 9:57 AM, Arseni Grigorjev wrote:
> 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.
>
>