问题:
public class PhoneControl {
private String IMEI;
private String IMEI2;
private String SN;
private String verifyCode;
对如下JSON数据 ,
{"verifyCode":"23333333","SN":"3903C18704D00047","IMEI":"111112222334234","IMEI2":"111112222334234"}
进行转换时,报错如下:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "SN" (class com.test.vo.PhoneControl), not marked as ignorable (4 known properties: "imei", "imei2", "sn", "verifyCode"])
at [Source: (String)"{"verifyCode":"23333333","SN":"3903C18704D00047","IMEI":"111112222334234","IMEI2":"111112222334234"}"; line: 1, column: 32] (through reference chain: com.tplink.vo.PhoneControl["SN"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
解决方法:
public class PhoneControl {
@JsonProperty(value = "IMEI")
private String IMEI;
@JsonProperty(value = "IMEI2")
private String IMEI2;
@JsonProperty(value = "SN")
private String SN;
private String verifyCode;