解析com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段

时间:2018-03-15 20:07:59

标签: java jax-rs

这次example works对我来说很好。但是,当我将Person类更改为以下内容时:

package com.thejavageek.jaxrs.model;

public class Person {


private int userSelectList;

    public int getUserSetSelectList() {
        return userSelectList;
    }

    public void setUserSetSelectList(int userSelectList) {
        this.userSelectList = userSelectList;
    }





    @Override
    public String toString() {

        return "Person [userSelectSet=" + userSelectList + "]";
    }

}

我通过传递JSON进行测试,如下所示:

enter image description here

错误:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "userSelectList" (class com.thejavageek.jaxrs.model.Person), not marked as ignorable (one known property: "userSetSelectList"])
 at [Source: io.undertow.servlet.spec.ServletInputStreamImpl@6418702f; line: 1, column: 20] (through reference chain: com.thejavageek.jaxrs.model.Person["userSelectList"])

为什么我上面分享的链接的示例工作得很好而不是这个?

1 个答案:

答案 0 :(得分:1)

在你的json中,将“userSelectList”更改为“userSetSelectList”,或将你的setter更改为“setUserSelectList”