Java Spring Jackson-未识别字段\“;答复\“;在任何时候都不被标记为可忽略的

Java Spring Jackson-未识别字段\“;答复\“;在任何时候都不被标记为可忽略的,java,json,jackson,Java,Json,Jackson,我需要将带有jackson的jSon字符串序列化为一个对象 我得到的线是 {"response":{"status":1,"count":"90120"}} 我的目标是 @JsonRootName("response") @JsonIgnoreProperties(ignoreUnknown = true) public class Wrapper { private String count; private int status; private String

我需要将带有jackson的jSon字符串序列化为一个对象

我得到的线是

{"response":{"status":1,"count":"90120"}}
我的目标是

@JsonRootName("response")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Wrapper {

    private String count;

    private int status;

    private String registration_error;

    private int usable;

// getters and setters
所以,这就是我如何得到我的包装

String response = {"response":{"status":1,"count":"90120"}};
        ObjectMapper mapper = new ObjectMapper();
        Wrapper w = mapper.readValue(response, Wrapper.class);
但是当我记录下来的时候,我得到了

Wrapper [count=null, status=0, registration_error=null, usable=0]
怎么了


谢谢

您正在使用@jsonRootName注释,这是正确的。但是,注释本身不起作用。您必须为对象映射器配置反序列化功能。您的代码应该如下所示:

    String response="{\"response\":{\"status\":1,\"count\":\"90120\"}}";
            ObjectMapper mapper = new ObjectMapper();

            mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

 //mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true); This is for serailization time
            Wrapper wrapper = mapper.readValue(response, Wrapper.class);

检查包装器,它具有json中给定的计数和状态。

您是否打算使用
@JsonRootName
?是的,我尝试了
@JsonRootName
@JsonTypeName
。。。同样的错误您确定使用的是
org.codehaus.jackson
注释而不是
com.fasterxml.jackson
?是的。。。检查了两次我所有关于jacksonWorks的进口对我来说很好。请在[Source:{“response:{“status”:1,“count:“90127”};第1行,第2列]发布一个.i'm getting此异常
com.fasterxml.jackson.databind.JsonMappingException:根名称“response”与类型[simple type,class it.besmart.easyparking.web.client.Wrapper]的预期('Wrapper'))不匹配
看起来您要么在包装类的顶部添加了@JsonRootName(“response”),要么将其更改为@JsonRootName(“Wrapper”)。根据您的json,@JsonRootName应该设置为“response”,因为response是json的顶级键。您有机会检查一下吗?