用到ToStringBuilder.reflectionToString方法
1.数据格式
[{
"action": "updateByUniqueId",
"entitlements": [
{
"guid": "c9d3175e8bff4abeaad2fcf066533159",
"entitlementType": "test_yongjun_001",
"createdBy": "756bfc3d70c24936a9277aa25524015a",
"createdOn": 1425398400000,
"changedBy": "756bfc3d70c24936a9277aa25524015a",
"changedOn": 1425398400000,
"entitlementNo": 998,
"entitlementDescription": "SAP Innovation managerment",
"quantity": 50,
"uom": "EA",
"validFrom": 1493913600001,
"validTo": 1586016000000,
"status": "Active",
"customerId": "C1011",
"customerName": "IBM",
"distributorId": "123",
"distributorName": "ABC",
"sourceSystem": "S4",
"refDocType": "Contract",
"refDocNo": "S1001268",
"refItemNo": "1",
"simulationEntitlementNo":123,
"generationMethod": "auto",
"version":1243,
"reason":"update",
"comments":"comments",
"YJ001":"kb"
}]
}
]
}
]
2.我把它通过spring mvc映射到dto上,重写toString()方法,我接收的Dto格式是:
public class EntitlementRepositoryApiDto implements Serializable
{
private static final long serialVersionUID = -9131473596527559855L;
private String action;
private List<Map<String, Object>> entitlements;
public String getAction()
{
return action;
}
public void setAction(String action)
{
this.action = action;
}
public List<Map<String, Object>> getEntitlements()
{
return entitlements;
}
public void setEntitlements(List<Map<String, Object>> entitlements)
{
this.entitlements = entitlements;
}
@Override
public String toString()
{
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
*ps:该方法可以嵌套输出多层Dto对象,非常好用!*