我计划将 JAXB 对象列表序列化为 JSON 响应。目前以下是我得到的格式。在下面的响应中,我看到中间的另一个对象是“systemInfoList”,它实际上正在显示数组。相反,我希望dependent_systems_infos 应该直接显示数组[]。此外,如果有单个系统信息响应,它也应该以数组格式显示。我正在使用杰克逊解析器,cxf。
目前我得到的格式:
{
"dependent_systems_infos":{
"systemInfoList":[
{
"system_name":"PZ_Service",
"system_type":"Internal",
"service_infos":[
{
"service_name":"getPZAttributes",
"status":"DOWN",
"response_time_ms":50
}
]
},
{
"system_name":"OMS",
"system_type":"External",
"service_infos":[
{
"service_name":"CreateOrder",
"status":"UP",
"response_time_ms":2000
},
{
"service_name":"CancelOrder",
"status":"UP",
"response_time_ms":500
}
]
}
]
}
}
我需要的格式:
{
dependent_system_infos : [
{
system_name : 'OMS'
system_type: 'External'
services_infos: [
{
service_name : 'CreateOrder'
status : 'UP'
response_time_ms : 2000
},
{
service_name : 'CancelOrder'
status : 'UP'
response_time_ms : 2000
}
]
},
{
system_name : 'PZ_Service'
system_type: 'Internal'
services_infos: [
{
service_name : 'getPZAttributes'
status : 'UP'
response_time_ms : 2000
}
]
}
]
}
我写的 JAXB 类:
@XmlRootElement(name = "dependent_systems_infos")
@XmlAccessorType(XmlAccessType.FIELD)
public class ItineraryStatusResponse {
private List<SystemInfo> systemInfoList;
@XmlList
public List<SystemInfo> getSystemInfoList() {
return systemInfoList;
}
public void setSystemInfoList(List<SystemInfo> systemInfoList) {
this.systemInfoList = systemInfoList;
}
}
@XmlType(propOrder = {
"systemName",
"systemType",
"serviceInfoList"
})
@XmlAccessorType(XmlAccessType.FIELD)
public class SystemInfo {
@XmlElement(name = "system_name", required = true)
protected SystemName systemName;
@XmlElement(name = "system_type", required = true)
protected SystemType systemType;
@XmlElement(name = "service_infos", required = true)
protected List<ServiceInfo> serviceInfoList;
}