更新时间:2023-11-16 22:13:52
默认情况下,Jackson尝试将Java Maps序列化为JSON对象(键/值对),因此Map key对象必须以某种方式序列化为String;并且必须有匹配的(和注册的)密钥反序列化器.默认配置仅支持一小部分JDK类型(字符串,数字,枚举).因此,映射器不知道如何获取String并从中创建AutoHandlingSlotKey.(实际上,我很惊讶序列化程序没有因相同的原因而失败)
By default, Jackson tries to serialize Java Maps as JSON Objects (key/value pairs), so Map key object must be somehow serialized as a String; and there must be matching (and registered) key deserializer. Default configuration only supports a small set of JDK types (String, numbers, enum). So mapper has no idea as to how to take a String and create AutoHandlingSlotKey out of it. (in fact I am surprised that serializer did not fail for same reason)
解决此问题的两种明显方法是:
Two obvious ways to solve this are:
就您而言,做前者可能更容易.您可能还需要实现自定义密钥序列化程序,以确保密钥是正确格式的序列化程序.
In your case it is probably easier to do former. You may also want to implement custom key serializer, to ensure keys are serializer in proper format.
注册序列化器和反序列化器的最简单方法是通过模块接口(已在Jackson 1.7(和在1.8中进行了扩展,以支持密钥序列化器/反序列化器.
The easiest way to register serializers and deserializers is by Module interface that was added in Jackson 1.7 (and extended in 1.8 to support key serializers/deserializers).