java json not marked as ignorable_Java json转object报错:Unrecognized field xxx , not marked as ignorabl...

json转object正常操作

ObjectMapper objectMapper = new ObjectMapper();

// targetObject:转换后的对象

Object targetObject = objectMapper.readValue(jsonString, targetObject.class);

// 如果json中存在目标对象Object不存在的字段,则会报错:Unrecognized field xxx , not marked as ignorable

需要加上下面的语句,才可正常转换

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

也可以直接在整个类上面加上注解

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)

public class newClass {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值