无法构建 - 杰克逊的实例 [英] Cannot construct instance of - Jackson

查看:230
本文介绍了无法构建 - 杰克逊的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用杰克逊而且我遇到了问题,当我尝试反序列化对象时出现以下错误:

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提供有关如何使用具体类型实例化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 Polymorphic反序列化

这篇关于无法构建 - 杰克逊的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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