Hi Jairo,
your use case seems a bit overcomplicated.
Please see [1] on how to configure Jackson based POJO JSON support
in Jersey (both server and client side should be covered).
Then all you need to do on the client side is:
MyClass v =
server.accept(MediaType.APPLICATION_JSON).get(MyClass.class);
see also [2] for an example.
Does it help?
~Jakub
[1]
http://jersey.java.net/nonav/documentation/latest/json.html#d4e894
[2]
http://download.java.net/maven/2/com/sun/jersey/samples/jacksonjsonprovider/1.6/jacksonjsonprovider-1.6-project.zip
On 04/13/2011 05:50 PM, Jairo1 wrote:
> Hi,
> I'm facing with the following issue:
>
> I'm trying to unmarshal the JSON data received from web server using this
> approach:
>
> ****************
> ClientResponse responseJ =
> server.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
> //Get the entity of the response
> String textEntityJ = (String)responseJ.getEntity(String.class);
>
> JSONJAXBContext contextJson = null;
> JSONUnmarshaller unmarshallerJson = null;
> MyClass myClassJson = null;
>
> //built JSONConfiguration based on mapped notation
> contextJson = new JSONJAXBContext(JSONConfiguration.natural().build(),
> MyClass.class);
> unmarshallerJson = contextJson.createJSONUnmarshaller();//create JSON
> Unmarshaller
>
> myClassJson = unmarshallerJson.unmarshalFromJSON(new
> StringReader(textEntityJ), MyClass.class);
> ***********
>
> Even I get the data in the 'textEntityJ' in the format
> {"version":["abb.123","xyz.456"]} the unmarshaller returns always MyClass
> object with empty List ( myClassJson.getVersion().size = 0).
>
> MyClass structure:
>
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
> "version"
> })
> @XmlRootElement(name = "versions")
> public class MyClass {
>
> protected List version;
>
>
> public List getVersion() {
> if (version == null) {
> version = new ArrayList();
> }
> return this.version;
> }
>
> }
>
>
> What could be wrong? The same issue I'm facing with XML approach. I receive
> data (as String) in the XML format, but unmarshaller failes in case when
> Java bean contains LIST object.
>
> Thanks in advance for your help,
> Jairo
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/JSON-XML-unmarshaller-problem-tp6269059p6269059.html
> Sent from the Jersey mailing list archive at Nabble.com.
>