我想在 java pojo 中将一个 json 字段设置为两个属性。当我在 pojo 中将 jsonproperty 用于重复属性时,一个字段每次都是空的。
我的 pojo 对象是;
public class PojoTest {
private String receiverAccountNo;
private String originalReceiverAccountNo;
@JsonProperty("receiverAccountNo")
public String getOriginalReceiverAccountNo() {
return originalReceiverAccountNo;
}
@JsonProperty("receiverAccountNo")
public void setOriginalReceiverAccountNo(String originalReceiverAccountNo) {
this.originalReceiverAccountNo = originalReceiverAccountNo;
}
public String getReceiverAccountNo() {
return receiverAccountNo;
}
public void setReceiverAccountNo(String receiverAccountNo) {
this.receiverAccountNo = receiverAccountNo;
}
}
我的要求是;
{
"receiverAccountNo":"566665"
}
我的测试控制器是;
@PostMapping("/test2")
public String test2(@RequestBody PojoTest pojoTest) {
return "OriginalReceiverAccountNo:"+pojoTest.getOriginalReceiverAccountNo()+" ReceiverAccountNo:"+pojoTest.getReceiverAccountNo();
}
当我运行代码时,我得到以下响应;
OriginalReceiverAccountNo:566665 ReceiverAccountNo:null
我正在使用 jackson-annotation-2.9.0 依赖项。我该如何解决这个问题?
BIG阳
慕婉清6462132
相关分类