java json not marked as ignorable_带有JSON的杰克逊:无法识别的字段,未标记为可忽略 - Jackson with JSON: Unrecognized field...

问题:

I need to convert a certain JSON string to a Java object. 我需要将某个JSON字符串转换为Java对象。 I am using Jackson for JSON handling. 我正在使用Jackson进行JSON处理。 I have no control over the input JSON (I read from a web service). 我无法控制输入的JSON(我从Web服务读取)。 This is my input JSON: 这是我输入的JSON:

{"wrapper":[{"id":"13","name":"Fred"}]}

Here is a simplified use case: 这是一个简化的用例:

private void tryReading() {

String jsonStr = "{\"wrapper\"\:[{\"id\":\"13\",\"name\":\"Fred\"}]}";

ObjectMapper mapper = new ObjectMapper();

Wrapper wrapper = null;

try {

wrapper = mapper.readValue(jsonStr , Wrapper.class);

} catch (Exception e) {

e.printStackTrace();

}

System.out.println("wrapper = " + wrapper);

}

My entity class is: 我的实体类是:

public Class Student {

private String name;

private String id;

//getters & setters for name & id here

}

My Wrapper class is basically a container object to get my list of students: 我的包装程序类基本上是一个容器对象,用于获取我的学生列表:

public Class Wrapper {

private List students;

//getters & setters here

}

I keep getting this error and "wrapper" returns null . 我不断收到此错误,“包装器”返回null 。 I am not sure what's missing. 我不确定缺少什么。 Can someone help please? 有人可以帮忙吗?

org.codehaus.jackson.map.exc.UnrecognizedPropertyException:

Unrecognized field "wrapper" (Class Wrapper), not marked as ignorable

at [Source: java.io.StringReader@1198891; line: 1, column: 13]

(through reference chain: Wrapper["wrapper"])

at org.codehaus.jackson.map.exc.UnrecognizedPropertyException

.from(UnrecognizedPropertyException.java:53)

解决方案:参考一:

https://stackoom.com/question/IpDX/带有JSON的杰克逊-无法识别的字段-未标记为可忽略

参考二:

https://oldbug.net/q/IpDX/Jackson-with-JSON-Unrecognized-field-not-marked-as-ignorable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值