com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ToUserName"

在调试公众号消息时,一直出现这个,原POJO为

public class MessageText {
    
    private String ToUserName;
    private String fromUserName;
    ******
    //get()  set()
}

错误信息为

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "FromUserName" (class club.fff.sss.MessageText), not marked as ignorable (2 known properties: "content", "ToUserName"])

查了很久资料解决了,方法是在每一个属性上加入

@JacksonXmlProperty(localName = "ToUserName")

public class MessageText {
    @JacksonXmlProperty(localName = "ToUserName")
    private String ToUserName;
    @JacksonXmlProperty(localName = "FormUserName")
    private String fromUserName;
    ******
    //get()  set()
}

即可。

你可能感兴趣的:(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ToUserName")