无法构建 - Jackson 的实例 [英] Cannot construct instance of - Jackson
本文介绍了无法构建 - Jackson 的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Jackson 并且遇到问题,当我尝试反序列化对象时,出现以下错误:
I am using Jackson and I'm having problems, when I try to deserialize an Object I get the following error:
com.fasterxml.jackson.databind.JsonMappingException:
Can not construct instance of net.MyAbstractClass,
problem: abstract types either need to be mapped to concrete types,
have custom deserializer, or be instantiated with additional type information
我的属性有问题:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT, property = "@id")
@JsonSubTypes({ @JsonSubTypes.Type(value = MyAbstractClass.class, name = "MyAbstractClass") })
@ManyToOne
private MyAbstractClass object;
有人可以帮我吗?
推荐答案
您不能实例化抽象类,Jackson 也不能.您应该向 Jackson 提供有关如何使用具体类型实例化 MyAbstractClass 的信息.
You cannot instantiate an abstract class, Jackson neither. You should give Jackson information on how to instantiate MyAbstractClass with a concrete type.
在stackoverflow上看到这个答案:Jackson JSON 库:如何实例化包含抽象字段的类
See this answer on stackoverflow: Jackson JSON library: how to instantiate a class that contains abstract fields
也许还可以参见 Jackson 多态反序列化
这篇关于无法构建 - Jackson 的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文