users@jersey.java.net

[Jersey] JSON response UnmarshalException

From: Christopher Schmidt <fakod666_at_googlemail.com>
Date: Mon, 20 Dec 2010 22:16:24 +0100

Hi all, I asked this already, so I hope that my mail got lost ;-)

I have the following response from a POST call:

[ {
  "start" : "http://localhost:7474/db/data/node/3",
  "nodes" : [ "http://localhost:7474/db/data/node/3", "
http://localhost:7474/db/data/node/1" ],
  "length" : 1,
  "relationships" : [ "http://localhost:7474/db/data/relationship/6" ],
  "end" : "http://localhost:7474/db/data/node/1"
}, {
  "start" : "http://localhost:7474/db/data/node/3",
  "nodes" : [ "http://localhost:7474/db/data/node/3", "
http://localhost:7474/db/data/node/2" ],
  "length" : 1,
  "relationships" : [ "http://localhost:7474/db/data/relationship/2" ],
  "end" : "http://localhost:7474/db/data/node/2"
} ]


And I try to unmarshal it to the following "JSON" object:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Traverse {
}

The client code I use now is (POST with JASONArray works fine):

GenericType<Collection<Traverse>> genericType = new
GenericType<Collection<Traverse>>() {};
webResource.path("node/3/traverse/path")
 .accept(MediaType.APPLICATION_JSON)
 .type(MediaType.APPLICATION_JSON)
 .post(genericType, "{\"order\":\"depth first\", \"max depth\": 1}");


I get the exception:

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"",
local:"start"). Expected elements are <{}traverse>
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)

Any advice? What else can I try?

-- 
Christopher
twitter: @fakod
blog: http://blog.fakod.eu