UnrecognizedPropertyException对我没有意义

问题描述 投票:1回答:1

我有一个JSON映射,包含一个简单的数据类型(String)和一个复杂的数据类型。我已经创建了一个结构来处理这个问题。这里是:

public static class PayloadData {
    String authkey;
    PizzaPlaceTo pizzaPlace;
    Map<String, List<String>> updates;
}

现在,我像这样读取数据:

    PayloadData payloadData = objectMapper.readValue(payload, PayloadData.class);

它给了我:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "authkey" (class pizzainthecloud.pizzaplace.controller.PizzaPlaceController$PayloadData), not marked as ignorable (0 known properties: ])
 at [Source: {"authkey":"Don't Panic!","pizzaPlace":{"contactName":null,"customerId":null}; line: 1, column: 13] (through reference chain: pizzainthecloud.pizzaplace.controller.PizzaPlaceController$PayloadData["authkey"])

所以,如果我正确地读到这个,它告诉我接收类中没有authkey来接收JSON数据中的authkey,对吧?只有。

请帮忙。

java json jackson
1个回答
0
投票

因此,看起来杰克逊只使用bean而不是结构样式类。我把班级改为:

public static class PayloadData {
    private String authkey;
    private PizzaPlaceTo pizzaPlace;
    private Map<String, List<String>> updates;

    public String getAuthkey() {
        return authkey;
    }

    public void setAuthkey(String authkey) {
        this.authkey = authkey;
    }

    public PizzaPlaceTo getPizzaPlace() {
        return pizzaPlace;
    }

    public void setPizzaPlace(PizzaPlaceTo pizzaPlace) {
        this.pizzaPlace = pizzaPlace;
    }

    public Map<String, List<String>> getUpdates() {
        return updates;
    }

    public void setUpdates(Map<String, List<String>> updates) {
        this.updates = updates;
    }
}

这解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.