gpt4 book ai didi

java - UnrecognizedPropertyException 对我来说没有意义

转载 作者:太空宇宙 更新时间:2023-11-04 10:40:17 24 4
gpt4 key购买 nike

我有一个 JSON 映射,其中包含简单数据类型(字符串)和复杂数据类型。我创建了一个结构来处理这个问题。这是:

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,对吗?只有这样。

请帮忙。

最佳答案

所以,看起来 Jackson 只适用于 bean,而不适用于结构样式类。我将类(class)更改为:

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;
}
}

问题就这样解决了。

关于java - UnrecognizedPropertyException 对我来说没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49056764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com