Feature: JsonNode findXxx() methods

(see Jira entry JACKSON-210 for details)

Prior to 1.6, finding values of JSON Object properties within large JSON structures required explicit code for recursive traversal. But with 1.6, you can do simple searchs. Consider following JSON structure:

  {
    "users" : [
      { "name" : "Bill" },
      { "name" : "David" },
      { "name" : "Brian,
        "type" : "architect" }
    ],
    "extra" : {
      "hostSettings" : { "domain" : "foo.com" }
    }
  }

to find values of all "name" properties, you could use:

  List<JsonNode> values = rootNode.findValues("name");

  // or, to automatically convert to String values:

  List<String> names = rootNode.findValuesAsText("name");

or just for a single value:

  JsonNode hostSettings = root.findValue("hostSettings");

and finally, if you want to find JSON object(s) that has/have a value for specified field, you can use:

  // would return user entry for 'Brian'
  JsonNode nodeWithType = root.findParent("type");


CategoryJackson

JacksonFeatureTreeFindValue (last edited 2010-08-05 06:51:53 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC