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

属性加public 修饰可解决。

例:

    public static class Apple {
        int price;
    }

    public void test2() {
        ObjectMapper objectMapper = new ObjectMapper();
        String jsonApple = "{\"price\":100}";
        Apple apple = new Apple();
        try {
            apple = objectMapper.readValue(jsonApple, Apple.class);
            System.out.println("apple price:" + apple.price);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

price 属性加public 修饰可解决:

public static class Apple {
    public int price;
}

猜你喜欢

转载自blog.csdn.net/wuzhong8809/article/details/105767872