Browse Source

Merge pull request #98 from platan/patch-1

Tweaking configuration examples with current API
pull/102/head
kallestenflo 10 years ago
parent
commit
244c3e2cbe
  1. 12
      README.md

12
README.md

@ -308,16 +308,16 @@ This option makes JsonPath return null for missing leafs. Consider the following
Configuration conf = Configuration.defaultConfiguration(); Configuration conf = Configuration.defaultConfiguration();
//Works fine //Works fine
String gender0 = JsonPath.using(conf).read(json, "$[0]['gender']"); String gender0 = JsonPath.using(conf).parse(json).read("$[0]['gender']");
//PathNotFoundException thrown //PathNotFoundException thrown
String gender1 = JsonPath.using(conf).read(json, "$[1]['gender']"); String gender1 = JsonPath.using(conf).parse(json).read("$[1]['gender']");
Configuration conf2 = conf.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL); Configuration conf2 = conf.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
//Works fine //Works fine
String gender0 = JsonPath.using(conf2).read(json, "$[0]['gender']"); String gender0 = JsonPath.using(conf2).parse(json).read("$[0]['gender']");
//Works fine (null is returned) //Works fine (null is returned)
String gender1 = JsonPath.using(conf2).read(json, "$[1]['gender']"); String gender1 = JsonPath.using(conf2).parse(json).read("$[1]['gender']");
``` ```
**ALWAYS_RETURN_LIST** **ALWAYS_RETURN_LIST**
@ -328,9 +328,9 @@ This option configures JsonPath to return a list even when the path is `definite
Configuration conf = Configuration.defaultConfiguration(); Configuration conf = Configuration.defaultConfiguration();
//Works fine //Works fine
List<String> genders0 = JsonPath.using(conf).read(json, "$[0]['gender']"); List<String> genders0 = JsonPath.using(conf).parse(json).read("$[0]['gender']");
//PathNotFoundException thrown //PathNotFoundException thrown
List<String> genders1 = JsonPath.using(conf).read(json, "$[1]['gender']"); List<String> genders1 = JsonPath.using(conf).parse(json).read("$[1]['gender']");
``` ```
**SUPPRESS_EXCEPTIONS** **SUPPRESS_EXCEPTIONS**
<br/> <br/>

Loading…
Cancel
Save