Java 映射键为null时找不到键反序列化器

Java 映射键为null时找不到键反序列化器,java,serialization,jackson,Java,Serialization,Jackson,在经历了类似的问题之后,我仍然无法解决这个问题。我正在使用Jackson对没有匹配getter/setters方法的类进行序列化和反序列化 public class Products implements Serializable { private static final long serialVersionUID = 1L; @JsonProperty private final Map<Product, String> prices; public Products() {

在经历了类似的问题之后,我仍然无法解决这个问题。我正在使用
Jackson
对没有匹配getter/setters方法的类进行序列化和反序列化

public class Products implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty
private final Map<Product, String> prices;

public Products() {
    this.prices = new HashMap<>();
}

public void addPrice(final Product product, final String price) {
    prices.put(product, price);
}
}
JsonDataConverter
我使用的是来自AWS流程框架的:

我在反序列化步骤中遇到的异常是:
在映射键“null”时,找不到类型[simple type,class mypackage.Product]的(映射)键反序列化器。

我无法理解这一点,因为我的
prices
map不包含任何空值。奇怪的是,如果
产品
只有一个成员(仅
名称
)字段,它就可以正常工作

知道出了什么问题吗


谢谢

您可以尝试修改product和products类的构造函数,使其具有JsonCreator注释,并使用JsonProperty注释每个参数

例如:

@JsonCreator
public Product(@JsonProperty("price") final String price, @JsonProperty("type") final String type) {
       this.name = price; this.type = type;
}

看起来问题在于产品映射有一个复合键。Jackson需要知道如何将其转换为字符串。@Alexey,可能是,但它可以序列化。而且,如果
Product
类中只有一个成员,那么一切都可以正常工作。所以我不确定这是否是问题所在。你想要的JSON格式是什么?只要JSON格式成功序列化和反序列化,我就不太担心它。我也有同样的问题,它序列化很好,但反序列化时我有问题。它给出了以下错误:-没有为类型[简单类型,类org.joda.time.chrono.ISOChronology]找到合适的构造函数]:无法从JSON对象实例化(需要添加/启用类型信息?)
@JsonCreator
public Product(@JsonProperty("price") final String price, @JsonProperty("type") final String type) {
       this.name = price; this.type = type;
}