SpringMVC json 转换中错误的解决: Unrecognized field , not marked as ignorable
来源:互联网 发布:nosql和sql有什么不同 编辑:程序博客网 时间:2024/05/16 12:11
在使用Json传值并且使用@RequestBody注解的时候需要注意一些问题:
- 一个方法中只能有一个@RequestBody注解。
- 默认情况下@RequestBody标注的对象必须包含前台传来的所有字段。
第一条容易理解,因为RequestBody就是request的inputStream,这个流在第一次使用该注解后会关闭,后面的都会报错(stream closed)。
第二条如果没有包含前台传来的字段,就会报错:Unrecognized field xxx , not marked as ignorable,这是因为MappingJacksonHttpMessageConverter默认要求必须存在相应的字段。如果没有前台传来的某个字段,就会报错。。
解决方法有很多,可以增加一个字段来接收前台传来的这个值,如果存在多个字段,这种方式很不好(就算一个字段,如果没用,新增字段也不好)。
或者在前台往后台传值的时候,去掉无用的字段。这样还能减少网络传输的大小。
还有一些方法,这些方法主要是使用Jackson提供的json注解。
@JsonIgnore注解用来忽略某些字段,可以用在Field或者Getter方法上,用在Setter方法时,和Filed效果一样。这个注解只能用在POJO存在的字段要忽略的情况,不能满足现在需要的情况。
@JsonIgnoreProperties(ignoreUnknown = true),将这个注解写在类上之后,就会忽略类中不存在的字段,可以满足当前的需要。这个注解还可以指定要忽略的字段。使用方法如下:
@JsonIgnoreProperties({ "internalId", "secretKey" })
指定的字段不会被序列化和反序列化。
注意:对于使用fasterxml版本的jackson,得import下面的注释
import com.fasterxml.jackson.annotation.*;
@JsonIgnoreProperties(ignoreUnknown = true)
public Myclass {
....
}
- SpringMVC json 转换中错误的解决: Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- 解决 Unrecognized field xxx , not marked as ignorable 问题
- 问题:Unrecognized field , not marked as ignorable
- Unrecognized field , not marked as ignorable
- Jackson 使用遇到 Unrecognized field, not marked as ignorable
- @RequestBody:Unrecognized field , not marked as ignorable问题
- JackSon反序列化报错,Unrecognized field, not marked as ignorable
- not marked as ignorable
- UnrecognizedPropertyException: Unrecognized field “***” ignorable
- not marked as ignorable JDBC like%?% Tomcat 启动一闪而过
- could not read json : unrecognized field "$$hashkey"
- Jackson2JsonRedisSerializer报错Could not read JSON: Unrecognized field...
- 关于SpringMVC中org.springframework.beans.factory.BeanCreationException: Could not autowire field:的问题的解决
- mysql--union
- APP保活
- 控制台出现 jQuery 1.9 .live() is not a function 解决方法
- Pandas中ix,loc,iloc有什么区别?
- 题目1440:Goldbach's Conjecture
- SpringMVC json 转换中错误的解决: Unrecognized field , not marked as ignorable
- 认识docker(一)
- network 多线程聊天
- 欢迎使用CSDN-markdown编辑器
- 第5次实验报告
- undefined is not an object (evaluating 'dataSource.rowIdentities')
- 单链表的实现及其操作
- 题目1441:人见人爱 A ^ B
- Unity.VR.05之3D凝视进度条的实现