gpt4 book ai didi

java - Jackson反序列化错误: MismatchedInputException

转载 作者:行者123 更新时间:2023-12-01 17:45:46 26 4
gpt4 key购买 nike

我有以下类(class)

public class Cart {
private final String id;

public Cart(String id) { this.id = id;}

public String getId() { return id; }
}

以及以下测试:

    String jsonString = "{\"id\":\"56c7b5f7-115b-4cb9-9658-acb7b849d5d5\"}";
Cart cart = mapper.readValue(jsonString, Cart.class);
assertThat(cart.getId()).isEqualTo("56c7b5f7-115b-4cb9-9658-acb7b849d5d5");

我收到以下错误:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.store.domain.model.Cart (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (String)"{"id":"56c7b5f7-115b-4cb9-9658-acb7b849d5d5"}"; line: 1, column: 2]

我不明白这里出了什么问题。请问有什么帮助吗?

最佳答案

您应该添加一个不带任何参数的普通构造函数,如下所示:

public Cart() { }

关于java - Jackson反序列化错误: MismatchedInputException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55529028/

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