[英]Remove all elements from objectnode in jackson
我有以下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]]]
}
}
]
}
基本上,我想從屬性中刪除所有元素,並得到類似:
"properties":{}
我嘗試過使用以下內容,但會刪除所有內容:
bufferPolygon.setObject(((ObjectNode)bufferIteration).with("properties").removeAll().toString());
基本上,我想從
properties
刪除所有元素,並得到類似:"properties":{}
以下內容將為您提供所需的結果:
JsonNode tree = mapper.readTree(json);
for (JsonNode feature : tree.get("features")) {
((ObjectNode) feature).set("properties", mapper.createObjectNode());
}
String updatedJson = mapper.writeValueAsString(tree);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.