如何从地图中获取特定类型?

时间:2019-04-12 01:30:42

标签: java jackson jackson-databind jackson2

我有两个这样的POJO

class SomeSection extends LinkedHashMap<String, Object> {
    @Suppress({"unchecked"}) public <R> R computeTypedIfAbsent(
            String Key,
            Function<String, R> function) {
        return (R) computeIfAbsent(key, function);
    }
}

class SomeEntity extends SomeSection {
}

我成功创建了一个SomeEntity实例,其中包含一些SomeSection

SomeEntity entity = new SomeEntity();
entity.put("some", new SomeSection());

我意识到我无法从SomeSection的反序列化实例中获得SomeEntity的值。而且我束手无策

// with deserialized...
ofNullable(computeTypedIfAbsent(key, k -> null))
        .map(map -> {
            SomeSection section = new SomeSection();
            section.putAll(map);
            put(key, section); // I can do this all day!!!
            return section;
        });

有什么办法告诉杰克逊将LinkedHashMap<>映射到SomeSection

我正在寻找ValueInstantiator吗?

0 个答案:

没有答案
相关问题