我有一个JSON数组
{ "inList" :
[
{ "cmd" : "enqueue", "name" : "job1", "pri" : 4 },
{ "cmd" : "enqueue", "name" : "job2", "pri" : 3 },
{ "cmd" : "dequeue" },
{ "cmd" : "enqueue", "name" : "job3", "pri" : 0 },
{ "cmd" : "enqueue", "name" : "job4", "pri" : 1 },
{ "cmd" : "dequeue" }
]
}
我想使用强大的Jackson将JSON反序列化为java对象。
而我有命中类(我觉得它有什么不对劲)
public class InList {
private String[] inList;
private LinkedList<Object> jobs;
public InList() { }
public String[] getInList() {
return inList;
}
public void setInList(String[] inList) {
this.inList = inList;
}
public LinkedList<Object> getJobs() {
return jobs;
}
public void setJobs(LinkedList<Object> jobs) {
this.jobs = jobs;
}
}
当我试图反序列化JSON时,它就是不能命中类
ObjectMapper mapper = new ObjectMapper();
InList inList = null;
try {
inList = mapper.readValue(jsonStr, InList.class);
}
你能帮我弄明白吗?
谢谢你!
1条答案
按热度按时间hyrbngr71#
您的Bean类应该如下所示:-
第一个