我想在嵌套结构中添加2个节点。第一个是初始状态
INITIAL
{
"type" : "type",
"features" : [ {
"properties" : {
"staticText" : "1",
"assets" : {
"metaData" : {
"someMetaData"
}
}
}
} ],
}
我想添加"合并"one_answers";node"对象节点如下所示。那我就选下面这个了。
DESIRED
{
"type" : "type",
"features" : [ {
"merge" : {
"properties" : {
"staticText" : "1",
"assets" : {
"node": {
"metaData" : {
"someMetaData"
}
}
}
}
}
} ],
}
我想把空节点("jsonNodes"下面的代码,但没有成功。我如何在第二个嵌套节点声明?
root.with("merge").set("properties",jsonNodes);
https://github.com/octomix/josson
反序列化
Josson josson = Josson.fromJsonString(
"{" +
" "type" : "type"," +
" "features" : [ {" +
" "properties" : {" +
" "staticText" : "1"," +
" "assets" : {" +
" "metaData" : {" +
" "someMetaData" : "xxx"" +
" }" +
" }" +
" }" +
" } ]" +
"}");
转换
JsonNode node = josson.getNode(
"field(features" +
" .map(merge" +
" :field(properties" +
" .field(assets" +
" .map(node" +
" :field(metaData)" +
" )" +
" )" +
" )" +
" )" +
")");
System.out.println(node.toPrettyString());
输出{
"type" : "type",
"features" : [ {
"merge" : {
"properties" : {
"staticText" : "1",
"assets" : {
"node" : {
"metaData" : {
"someMetaData" : "xxx"
}
}
}
}
}
} ]
}