spring mvc 返回的json去掉null

在springmvc.xml中添加如下:

<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
           <property name="objectMapper">
               <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                   <property name="serializationInclusion">
                       <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
                   </property>
               </bean>
           </property>
        </bean>

但是有个问题就是以json作为参数的接口,bean必须和json对应好,否则会报

 at [Source: java.io.PushbackInputStream@4053f24; line: 1, column: 100] (through reference chain: com.neusoft.geexek.web.enroll.bean.
CompetitionRoadUser["IDNumber"]);
 nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "IDNumber" (class com.neusoft.geexek.web.
enroll.bean.CompetitionRoadUser),
 not marked as ignorable (54 known properties: "remark", "sumAmount", "groupNum", "shoesSize", "userMapId", "isTeamLeader", "platForm", "payTime",
 "dateOfBirth", "email", 
"isPay", "contactsAddress", "cert", "origin", "isTeam", "clothingSize", "auditStatus", "callPhone", "roleId", "updateTime", "trueName", "gender",
 "idNumber", "degree", "lot", "bloodType", "teamId", "contactsPhone", "health", "serialNumber", "noteIsSend", "createTime", "city", "payOrigin",
 "contactsRelation", "extraPayAmount", "note", "address", "isDelete", "userName", "teamSave", "extraPays", "contactsName", "typeOfID", "userPayRelations",
 "registerId", "cmptId", "isCancel", "amount", "roadId", "team", "isIns", "markNo", "role"])
 at [Source: java.io.PushbackInputStream@4053f24; line: 1, column: 100] (through reference chain: 
com.neusoft.geexek.web.enroll.bean.CompetitionRoadUser["IDNumber"])

我传递的json格式的参数数:

{"remark":"[]","userName":"123123123","callPhone":"123123123123","typeOfID":"身份证","IDNumber":"123123123123123","gender":0,"roadId":8553,"userPayRelations":[],"idNumber":"123123123123","isIns":2}


去除这种错误的办法:在bean上添加

@JsonIgnoreProperties(ignoreUnknown = true)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值