Hello Pengfei,
On 03/24/2011 10:29 AM, Pengfei Di wrote:
> Hello,
>
> I have some problem when I use ClientResponse.getEntity to parse a
> jaxb class from a JSON representation, if @JsonTypeInfo annotation is
> applied.
> Here is the code with problem:
>
> @JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT)
> @XmlRootElement
> public class MyTest
> {
> private int code;
> private String msg;
> //setter and getter
> }
>
> The Json string looks like:
> {"MyTest":{"code":207,"msg":"blah blah"}}
> and the parsed result of MyTest contains either 0 or null.
>
it seems, you do not have your client configured to use the JSON POJO
mapping feature (see [1]).
I have added this snippet to the Jersey user guide doc only recently:
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
Boolean.TRUE);
Client client = Client.create(clientConfig);
>
> However, if I remove the include part of the @JsonTypeInfo, there is
> no problem any more, and the Json string looks like:
> {"@type":"MyTest","code":207,"msg":"blah blah"}
>
That is strange, from top of my head, this does not seem to come from
Jackson,
but i might be mistaken.
Could you please confirm you use Jackson providers (POJO mapping) on both,
server and client side?
~Jakub
[1]
http://jersey.java.net/nonav/documentation/1.6-SNAPSHOT/json.html#d4e894
> Thanks a lot for any help!
>
> Pengfei
>
>