kidly检查下面的json。我想把它转换成pojo类。
我试过和下面的同学一起学习
@Data
public class Root {
@JsonProperty("0") // Dont want to pass like this. it should be single list and index is the key of that array
public List<Request> list;
@JsonProperty("1")
public List<Request> list1;
@JsonProperty("2")
public List<Request> list2;
@Data
private class Request {
int id;
String title;
int level;
List<Request> children;
@JsonProperty("parent_id")
int parentId;
}
}
{
"0": [
{
"id": 12123,
"title": "sfsdf",
"level": 0,
"children": [
],
"parent_id": null
}
],
"1": [
{
"id": 213,
"title": "d",
"level": 1,
"children": [
],
"parent_id": 1212312
},
{
"id": 3232,
"title": "dfsdf",
"level": 1,
"children": [
],
"parent_id": 42
},
{
"id": 234,
"title": "tder",
"level": 1,
"children": [
],
"parent_id": 122
}
],
"2": [
{
"id": 452,
"title": "Blll",
"level": 2,
"children": [
],
"parent_id": 322
},
{
"id": 123,
"title": "trrr",
"level": 11,
"children": [
],
"parent_id": 1221
},
{
"id": 33,
"title": "sdfw",
"level": 2123,
"children": [
],
"parent_id": 10
}
]
}
3条答案
按热度按时间o75abkj41#
路过
Map<String, List<Request>> lists
在控制器请求主体中。我的问题解决了。我得到了预期的json。py49o6xq2#
只需删除第二和第三个列表。只保留一个列表,让它保留它的名字,比如
list
或者requests
. 然后把它添加到列表中。33qvvth13#
使用
@JsonAnySetter
.示例,使用
public
为简单起见,字段:测试
输出