On Mon, Dec 20, 2010 at 5:09 AM, Tommy1199 <sascha...@gmail.com> wrote:
> Hi everyone,
>
> I try to use Gson (1.6) in combination with Jersey to work with the
> Neo4J REST api.
>
> One of the responses of Neo4J looks like this:
>
> [ {
> "start" : "http://localhost:7474/db/data/node/0",
> "nodes" : [ "http://localhost:7474/db/data/node/0", "http://
> localhost:7474/db/data/node/1" ],
> "length" : 1,
> "relationships" : [ "http://localhost:7474/db/data/relationship/
> 0" ],
> "end" : "http://localhost:7474/db/data/node/1"
> } ]
>
> and I try to deserialize it to a JsonArray with this code:
JsonArray is an internal json element representation of an array.
I don't think you can deserialize anything into JsonArray.
Gson generally is used for serilizing your structures, or deserializing into
your structures (your structures here means structures that you defined)
In this case, there is such definition offered.
Also, I believe that the above is not really a good json, but I may be mistaken.
Json.org is actually not particularly clear on what a valid Json stream is
(they say what json elements are, but the root element is not really defined.
They should've added "json := xxxx", for example "json := object |
array", but it may
be just "json := object"), so it may be so that valid json has to
start from object.
Typically, you'd need to define the object structure where you want
to load your data into. So you'd define an object which will contain whatever
things you expect in the response. I guess that if you don't know all
the things,
you'd need to pass over a map.
So it should be either:
MyObject[] jsonObjects = gson.fromJson(jsonText, MyObject[].class);
or
Map<String, Object>[] result = gson.fromJson(jsonText, HashMap[].class);