-----Original Message-----
From: KARR, DAVID
Sent: Monday, August 19, 2013 3:05 PM
To: [email protected]
Subject: RE: Debugging json WebClient unmarshal in older CXF (2.3.2) release
-----Original Message-----
From: KARR, DAVID
Sent: Monday, August 19, 2013 2:44 PM
To: [email protected]
Subject: Debugging json WebClient unmarshal in older CXF (2.3.2) release
I'm trying to put together a component that makes a WebClient request to a
JAX-RS (Jersey) REST service and unmarshals json into a Java object.
Unfortunately, I'm using CXF 2.3.2, and I can't really upgrade at this
point.
Just so it's clear, I'm going to need to be able to manually configure the
WebClient. I won't be able to use a Spring context for htis.
I was given the URL to send for the service, and I can see what JSON it's
returning. From that, I tried to construct a POJO with Xml annotations,
and
then I constructed the WebClient call to get the response and unmarshal
into
the POJO. I first did a query returning String, so I could verify I get
the
JSON at least. That part works fine.
The query that specifies the POJO type is failing, however.
When I defined the POJO, I only defined one property that I know is coming
in
the JSON. I just wanted to verify the single property gets set before I
defined more properties that I need to get. I assume other properties
present in the JSON will be ignored.
The response I get looks something like this:
{"copyright":"<copyright
stuff>","termsurl":"http://...","logourl":"http://...","status":200,"resp_cod
e":0,"results":[{"id":"M100"},{"id":"M101"}]}
My POJO looks like this:
@XmlType(name = "queryResponse")
@XmlRootElement(name = "queryResponse")
public class QueryResponse {
private String copyright;
@XmlElement
public String getCopyright() { return this.copyright; }
public void setCopyright(String copyright) { this.copyright =
copyright;
}
}
When I try to run the query, I get the following:
UnmarshalException: unexpected element (uri:"", local:"copyright").
Expected
elements are <{}queryResponse>]
Is the problem that I don't have a top-level element in the json called
"queryResponse"? If so, I can't change the service that's returning this
data.
In my pom, I'm specifying "cxf-rt-core", "cxf-rt-frontend-jaxrs", "cxf-rt-
databinding-jaxb", "cxf-rt-bindings-http", and "cxf-rt-transports-http".