我有两个这样的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
吗?