给定以下嵌套对象
{
"nestedParent":{
"type":"nested",
"dynamic":"true",
"properties":{
...
}
}
}
我也需要它的所有属性都是nested
类型。如何为未知数量的嵌套子项生成映射?
功能上等于:
{
"nestedParent":{
"type":"nested",
"dynamic":"true",
"properties":{
"nestedChild1":{
"type":"nested",
"dynamic":"true",
"properties":{
...
}
},
"nestedChild2":{
"type":"nested",
"dynamic":"true",
"properties":{
...
}
},
"nestedChild3":{
"type":"nested",
"dynamic":"true",
"properties":{
...
}
},
...
}
}
}
我确实知道嵌套子项的结构,但我不知道它们的键/名称。
您将需要一些通用的数据结构,例如地图的地图,以便映射未知结构。在Java中,这个问题有很多实现。例如,请看一下这篇文章,它描述了如何使用 te jackson 映射器处理(反)序列化未知 json: https://www.baeldung.com/jackson-json-node-tree-model