我最近也遇到这个问题:当实体A中有一个集合,集合有两个以上的元素(B实体),B中包含实体C和D等,使用JSON.toJSONString(A)时,序列化结果错误,无报错。结果为:集合中第一个元素完全正常,从第二个元素开始,C, D元素中只有一个元素能正确序列化。结果如下:
{
"code": 1,
"message": "success",
"data": [
{
"app": {
"appKey": "ESG3mLLV",
"code": "san",
"createdTime": "2019-07-08T11:02:38",
"description": "",
"id": 8,
"name": "test-Android",
"os": "ANDROID",
"updatedTime": "2019-07-08T11:02:38"
},
"appName": "test-Android",
"channel": {
"created_time": "2019-07-29T11:15:38",
"id": 8,
"name": "UC信息流",
"updated_time": "2019-07-29T11:15:36"
},
"type": 1
},
{
"app": {
"$ref": "$.data[0].app"
},
"appName": "test-Android",
"channel": {
"created_time": "2019-07-08T10:53:04",
"id": 6,
"name": "今日头条",
"updated_time": "2019-07-08T10:53:04"
},
"type": 1
},
{
"app": {
"$ref": "$.data[0].app"
},
"appName": "test-Android",
"channel": {
"created_time": "2019-07-08T10:53:04",
"id": 5,
"name": "爱奇艺",
"updated_time": "2019-07-08T10:53:04"
},
"type": 1
},
{
"app": {
"$ref": "$.data[0].app"
},
"appName": "test-Android",
"channel": {
"created_time": "2019-07-15T16:35:28",
"id": 7,
"name": "百度ocpc",
"updated_time": "2019-07-15T16:35:25"
},
"type": 1
}
]
}