【发布时间】:2018-02-01 18:03:03
【问题描述】:
我正在编写一个基于 jax-rs 的 rest API,其中我的响应将包含动态 json 键。在下面的响应中,json 键 Tom、Harry 是动态的,并且可以有更多。编写 java DTO 来表示结构并能够拥有动态员工姓名的最佳方法是什么?
"employee":{
"Tom":{
"id":"23974",
"name":"Tom L",
"jobRole":"Associate",
"contact":{
"phone":"8889993332",
"address":"some address"
},
"peers":[
"peer1",
"peer2"
]
},
"Harry":{
"id":"34234",
"name":"Harry S",
"jobRole":"Associate",
"contact":{
"phone":"3459993332",
"address":"some address"
},
"peers":[
"peer1",
"peer2"
]
}
}
}
【问题讨论】:
-
地图地图应该适合您
-
"dynamic json keys" =
Map---也就是说根对象的employee字段的类型是Map<String, Employee>。
标签: java json data-structures jax-rs dto