shau-lok / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Provide xpath like accessors for the Parse Tree #322

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
See the discussion at 
https://groups.google.com/forum/?hl=en#!topic/google-gson/DPTGYmbfI5c

Original issue reported on code.google.com by inder123 on 8 May 2011 at 8:20

GoogleCodeExporter commented 9 years ago
Issue 312 has been merged into this issue.

Original comment by inder123 on 3 Jun 2011 at 6:33

GoogleCodeExporter commented 9 years ago
The feature requester wanted to do this:
  String value = element.get("mystructure.myArray[3].myproperty");

I recommend that they just use the Java APIs:
  element.getAsJsonObject().get("mystructure")
    .getAsJsonObject().get("myArray")
    .getAsJsonArray().get(3)
    .getAsJsonObject().get("myproperty");

I admit that it's more verbose, but it's type safe and it will fail with a much 
more meaningful error.

Original comment by limpbizkit on 1 Jul 2011 at 9:51

GoogleCodeExporter commented 9 years ago
essentially defeats the intent of the original request - to have an xpath like 
construct.

Original comment by javadba@gmail.com on 7 Apr 2013 at 2:15

GoogleCodeExporter commented 9 years ago
a meaningful error is not at all difficult in case of of failure
moreover all the convenience methods of getString and the like still make sense

the feature originally described would make the library useful in a whole class 
of problems where json is a good enough structure for working with data and 
doing Java<->Json is not necessary

Original comment by un...@webgress.com on 5 Mar 2014 at 2:33