我有两个不同的数组列表类,即不同的实例,即
//来自Claims.java arraylist类的数据
List<Claim> list1 = new ArrayList<Claim>(claims.values());
打印出来
{
"claims": [
{
"id": 98879,
"Names": "Victor xxx"
},
{
"id": 80790,
"Names": "Mary xxx"
}
]
}
//来自ServiceTag.java arraylist类的数据
List<ServiceTag> list2 = new ArrayList<ServiceTag>(servicetag.values());
打印出来
{
"serviceTags": [
{
"quantity": 1,
"claimid": 98879,
"serviceType": pharmacy,
"cost": 100
},
{
"quantity": 1,
"claimid": 80790,
"serviceType": treatment,
"cost": 400
}
]
}
我想合并这两个列表并打印出基于声明的输出,即得到像
这样的东西{
"claims": [
{
"id": 98879,
"Names": "Victor xxx",
"serviceTags":
{
"quantity": 1,
"claimid": 98879,
"serviceType": pharmacy,
"cost": 100
}
},
{
"id": 80790,
"Names": "Mary xxx",
"serviceTags":
{
"quantity": 1,
"claimid": 80790,
"serviceType": treatment,
"cost": 400
}
}
]
}
答案 0 :(得分:1)
听起来你想要ServiceTag
({1}}每个Claim
的列表。因此,修改Claim
并添加类似
private List<ServiceTag> serviceTags = new ArrayList<>();
public List<ServiceTag> getServiceTags() {
return serviceTags;
}
public void addServiceTag(ServiceTag st) {
serviceTags.add(st);
}
public void addServiceTags(Collection<ServiceTag> sts) {
serviceTags.addAll(sts);
}