这是我的 JSON 数组:-
[
{
"firstName" : "abc",
"lastName" : "xyz"
},
{
"firstName" : "pqr",
"lastName" : "str"
}
]
我的 String 对象中有这个。现在我想将它转换为 Java 对象并将其存储在 Java 对象列表中。例如在学生对象中。我正在使用下面的代码将其转换为 Java 对象列表:-
ObjectMapper mapper = new ObjectMapper();
StudentList studentList = mapper.readValue(jsonString, StudentList.class);
我的列表类是:-
public class StudentList {
private List<Student> participantList = new ArrayList<Student>();
//getters and setters
}
我的学生对象是:-
class Student {
String firstName;
String lastName;
//getters and setters
}
我在这里错过了什么吗?我遇到了以下异常:-
Exception : com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.aa.Student out of START_ARRAY token