从 jackson 中的 objectnode 中删除所有元素
Remove all elements from objectnode in jackson
我有以下对象节点:
{
"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]]]
}
}
]
}
基本上我想从属性中删除所有元素并得到类似的东西:
"properties":{}
我试过使用以下内容,但它删除了所有内容:
bufferPolygon.setObject(((ObjectNode)bufferIteration).with("properties").removeAll().toString());
Basically I want to remove all the elements from properties
and get something like:
"properties":{}
以下应该会给您想要的结果:
JsonNode tree = mapper.readTree(json);
for (JsonNode feature : tree.get("features")) {
((ObjectNode) feature).set("properties", mapper.createObjectNode());
}
String updatedJson = mapper.writeValueAsString(tree);
我有以下对象节点:
{
"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]]]
}
}
]
}
基本上我想从属性中删除所有元素并得到类似的东西:
"properties":{}
我试过使用以下内容,但它删除了所有内容:
bufferPolygon.setObject(((ObjectNode)bufferIteration).with("properties").removeAll().toString());
Basically I want to remove all the elements from
properties
and get something like:"properties":{}
以下应该会给您想要的结果:
JsonNode tree = mapper.readTree(json);
for (JsonNode feature : tree.get("features")) {
((ObjectNode) feature).set("properties", mapper.createObjectNode());
}
String updatedJson = mapper.writeValueAsString(tree);