0

I have the following objectNode:

{
   "type": "FeatureCollection",
   "features": [
        {"type":"Feature",
         "properties":{
              "pro1":"value1",
              "pro2":"value2" 
         },
         "geometry":{
              "type":"Polygon",
              "coordinates":[[[3.22998,48.312428],[3.22998,48.719961],[3.405762,48.719961],[3.405762,48.312428],[3.22998,48.312428]]]
           }
         }  
      ]
}

Basically I want to remove all the elements from properties and get something like:

"properties":{}

I've tried top use the following but it deletes everything:

bufferPolygon.setObject(((ObjectNode)bufferIteration).with("properties").removeAll().toString());
Allain
  • 105
  • 10

1 Answers1

0

Basically I want to remove all the elements from properties and get something like:

"properties":{}

The following should give you the desired result:

JsonNode tree = mapper.readTree(json);
for (JsonNode feature : tree.get("features")) {
    ((ObjectNode) feature).set("properties", mapper.createObjectNode());
}

String updatedJson = mapper.writeValueAsString(tree);
cassiomolin
  • 124,154
  • 35
  • 280
  • 359