找不到类型[simple type,com.comcast.ivr.core.domain.AutoHandlingSlotKey]类型的(Map)密钥反序列化器 [英] Can not find a (Map) Key deserializer for type [simple type, class com.comcast.ivr.core.domain.AutoHandlingSlotKey]

查看:342
本文介绍了找不到类型[simple type,com.comcast.ivr.core.domain.AutoHandlingSlotKey]类型的(Map)密钥反序列化器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有地图的域对象:

I have a domain object that has a Map:

private Map<AutoHandlingSlotKey, LinkedHashSet<AutoFunction>> autoHandling;

当我序列化对象时,我得到了这个:

When I serialize the object, I get this:

"autoHandling" : [ "java.util.HashMap", {
} ],

这个Map的键是一个自定义对象:

This Map's key is a custom Object:

public class AutoHandlingSlotKey implements Serializable {
    private FunctionalArea slot; // ENUM
    private String returnView;   // ENUM

所以,我不知道如何纠正这个问题,当我反序列化对象:

So, I am not sure how to correct this issue I keep getting when I deserialize the object:

org.codehaus.jackson.map.JsonMappingException: Can not find a (Map) Key deserializer for type [simple type, class com.comcast.ivr.core.domain.AutoHandlingSlotKey]

有人可以帮我理解如果 NOT 有权访问要修改的域对象,请更正此问题?

Can someone help me to understand how to correct this issue if I do NOT have access to the domain object to modify?

推荐答案

按默认情况下,Jackson尝试将Java Maps序列化为JSON对象(键/值对),因此Map键对象必须以某种方式序列化为String;并且必须有匹配(和注册)密钥解串器。默认配置仅支持一小组JDK类型(字符串,数字,枚举)。
因此mapper不知道如何获取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).

这篇关于找不到类型[simple type,com.comcast.ivr.core.domain.AutoHandlingSlotKey]类型的(Map)密钥反序列化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆