以下JSON有一些父子关系(样本数据)
像这样我有大量数据
{
"statusCode": 200,
"statusMessage": "Success",
"dataCount": 0,
"data": null,
"dataList": [
{
"id": 1050,
"parentId": 1051,
"questionInfo": {
"id": 1050,
"description": "--",
"question": "--",
"answersInfo": [
{
"id": 2041,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
},
{
"id": 2040,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
}
]
}
},
{
"id": 1051,
"parentId": null,
"questionInfo": {
"id": 1051,
"description": "--",
"question": "--",
"answersInfo": [
{
"id": 2024,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
},
{
"id": 2023,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": [
{
"id": 1050,
"parentId": 1051,
"questionInfo": {
"id": 1050,
"description": "--",
"question": "--",
"answersInfo": [
{
"id": 2041,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
},
{
"id": 2040,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
}
]
}
}
]
}
]
}
},
{
"-------": "-------"
}
],
"dataMap": null
}
我的要求是需要从父位置移除子记录,其中parentId具有某个值(“parentId”:1051),因为这些子信息来自父子信息,这些记录不是父记录
{
"statusCode": 200,
"statusMessage": "Success",
"dataCount": 0,
"data": null,
"dataList": [
{
"id": 1051,
"parentId": null,
"questionInfo": {
"id": 1051,
"description": "--",
"question": "--",
"answersInfo": [
{
"id": 2024,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
},
{
"id": 2023,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": [
{
"id": 1050,
"parentId": 1051,
"questionInfo": {
"id": 1050,
"description": "--",
"question": "--",
"answersInfo": [
{
"id": 2041,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
},
{
"id": 2040,
"description": "--",
"isCorrect": "--",
"name": "--",
"subQuestions": []
}
]
}
}
]
}
]
}
},
{
"-------": "-------"
}
],
"dataMap": null
}
我使用Spring MVC + Hibernate标准API + Jackson库 所以,有人可以告诉我在序列化时从列表中排除对象(基于某些条件的完整对象)的最佳方法吗?
答案 0 :(得分:0)
在我们与@Developer讨论时,回答此问题的最佳方法是使用某个工具序列化所有对象,就像ObjectMapper
中的Jackson
一样,并且一旦构建了List,迭代它只有你想要保留的元素。
性能方面,这不是最好的,但这将确保您不会错过任何想要的物品