【发布时间】:2015-04-29 00:41:14
【问题描述】:
以下是 JSON 字符串的外观
{
"employee": {
"id": "c1654935-2602-4a0d-ad0f-ca1d514a8a5d",
"name": "smith"
...
}
}
现在我正在使用ObjectMapper#readValue(jsonAsStr,Employee.class) 将其转换为 JSON。
我的Employee类如下...
@XmlRootElement(name="employee")
public class Employee implements Serializable {
private String id;
private String name;
...
public Employee() {
}
@XmlElement(name="id")
public String getId() {
return id;
}
public void setId(String id) {
this.id= id;
}
@XmlElement(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
...
}
我得到的例外是
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "employee" (class com.abc.Employee), not marked as
ignorable (12 known properties: , "id", "name", ... [truncated]])
我无法理解为什么“员工”被视为财产。假设只有类成员被视为属性,我错了吗?
【问题讨论】: