说我有两个类, CompactedA 是 A 的紧凑版本:
class A {
private String id = null;
private List<B> listB = new ArrayList<B>;
private String name = null;
private String age = null;
}
class CompactedA {
private String id = null;
private List<CompactedB> listCompactedB = new ArrayList<CompactedB>;
}
class B {
private String bId = null;
private String bName = null;
private String bAge = null;
}
class CompactedB {
private String bId = null;
}
现在我得到了一个CompactedA对象(称为ca
),其名称如下:
{
id : '001', // Id
[
{ bId : '001b'},
{ bId : '002b'},
{ bId : '003b'},
] // listCompactedB
}
如何基于a
的值新建一个对象ca
?
a
的结果应为:
{
id: '001',
[
{ bId: '001b', bName: null, bAge: null},
{ bId: '002b', bName: null, bAge: null},
{ bId: '003b', bName: null, bAge: null},
],
name: null,
age: null
}