我有一个Employee类,我想像这样序列化:
class Employee {
String name;
@JsonUnwrapped
EmployeeId id;
@JsonUnwrapped(prefix = "previousEmployee")
EmployeeId previousEmployeeId;
}
final class EmployeeId{
@JsonProperty("id")
private final long value;
@JsonCreator
public EmployeeId(@JsonProperty("id") long value) {
this.value = value;
}
}
序列化Employee给出以下 json:
{
"name":"foo",
"id" : 123,
"previousEmployeeid" : 456
}
但是,这previousEmployeeId是可选的。因此,如果我尝试反序列化这个 json,它会将 inid放入previousEmployeeId字段中。我究竟做错了什么?
{
"name":"foo",
"id" : 123
}
我希望该字段previousEmployeeid是,null但它被分配了一个值123。
慕无忌1623718
相关分类