我有一个JSON字符串如下:
{
"PhoneNumber": "0000000000",
"cart":
[
{
"Number": "1234",
"realm": "2345",
"id": "1234",
"quantity": "1"
}
],
"employeeId": "345",
"group": "10080",
"empEmail": "xyz@gmail.com",
}
如何使用inputbean
反序列化为objectmapper
?
inputBean = objectMapper.readValue(json.toString(), inputBean.getClass());
我收到错误
Can not deserialize instance of java.lang.String[]
out of START_OBJECT token\n at
答案 0 :(得分:4)
inputBean的类是什么?
要反序列化该JSON,您需要以下bean:
class InputBean {
String phoneNumber;
List<Cart> cart;
String employeeId;
String group;
String empEmail;
// Getters, setters and constructor omitted for brevity
}
class Cart {
String number;
String realm;
String id;
String quantity;
// Getters, setters and constructor omitted for brevity
}
然后用:
对其进行反序列化InputBean inputBean = objectmapper.readValue(json.toString(), InputBean.class);
您还应该查看您的JSON源材料,因为它在属性命名方面不一致,某些属性以大写字符开头,而某些属性以小写字符开头。