我已阅读JSONMappingException for External ObjectJSONMappingException for Class,但找不到ObjectNode类的解决方案。

通过阅读JSONMappingException for External Object
我了解您必须在mapper中注册Object,但在调用Web服务时尚未创建任何ObjectMapper类

mapper.registerModule(new GeoModule());


我正在尝试调用My POJO(ReportQueryData.java)的Web服务,其中包含ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)实例变量。

ReportQueryData.java

import com.fasterxml.jackson.databind.node.ObjectNode;

public class ReportQueryData {
    private ObjectNode parentsData;

    public ObjectNode getParentsData() {
        return parentsData;
    }

    public void setParentsData(ObjectNode parentsData) {
        this.parentsData = parentsData;
    }
}


现在,我在请求中调用包含ReportQueryData的Web服务,并且遇到以下异常

org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.fasterxml.jackson.databind.node.ObjectNode]: can not instantiate from JSON object (need to add/enable type information?)
[INFO] [talledLocalContainer]  at [Source: org.apache.catalina.connector.CoyoteInputStream@3da45801; line: 1, column: 155] (through reference chain: com.atlassian.qtm.model.ReportQueryData["parentsData"])
[INFO] [talledLocalContainer]   at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
[INFO] [talledLocalContainer]   at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObjectUsingNonDefault(BeanDeserializer.java:740)
[INFO] [talledLocalContainer]   at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:683)

最佳答案

您还必须为此类编写默认构造函数

public ReportQueryData (){

}


编辑::尝试在您的类中包装该类并使用您的类。

 class A{

    A(String s){

    }
}

class B extends A{

    B(){
        super("str");
    }
}

10-05 19:14