1

I am working over JsonNode and trying to get relativePath and add as attribute .

 public static void iterateOver(JsonNode masterJSON) {
    Iterator<Entry<String, JsonNode>> nodes = masterJSON.fields();
    while (nodes.hasNext()) {
      Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next();

      JsonNode value = entry.getValue();
      if(value.has("current") && value.has("older")) {
          System.out.println("key --> " + entry.getKey() + " value-->" + value);
          String relativePath = "";// ? how do get relative path e.g /obj/empdetails/data[0]/address;
          ((ObjectNode)entry.getValue()).put("relativePath", relativePath);
      }
      if(value.isArray()) {
           for (int i = 0; i < value.size(); i++) {
              iterateOver(value.get(i));
        }
      }else if (value.isObject()) {
          iterateOver(value);
      }
      
    }
}

i want to have relativePath in such a way that at i can get the exact object as node.at(relativePath)

  • Why are you trying this way when you have `ObjectMapper` in JACKSON2? Can you post you JSON Structure here?? – Avinash Apr 22 '21 at 06:20

0 Answers0