Unrecognized field , not marked as ignorable
来源:互联网 发布:中国的未来是一群正知 编辑:程序博客网 时间:2024/05/16 14:44
转自http://blog.csdn.net/isea533/article/details/33397735
在使用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" })
指定的字段不会被序列化和反序列化。
- 问题:Unrecognized field , not marked as ignorable
- Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- Jackson 使用遇到 Unrecognized field, not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- @RequestBody:Unrecognized field , not marked as ignorable问题
- 解决 Unrecognized field xxx , not marked as ignorable 问题
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
- JackSon反序列化报错,Unrecognized field, not marked as ignorable
- SpringMVC json 转换中错误的解决: 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...
- UnrecognizedPropertyException: Unrecognized field
- :last-child 选择器
- 51nod 1393 0和1相等串 思路
- openstack swift 文档(八):Java Storlet 编写和部署指导
- muduo源码学习(21)-TcpSever/TcpConnection
- jQuery实现多个邮箱格式验证,多个邮箱需使用英文逗号分隔
- Unrecognized field , not marked as ignorable
- go 语言怎么写test测试
- python入门(三十七):multiprocessing模块
- 归并排序算法原理分析与代码实现
- 表格增加行,增加按钮跟随在每一新增行的后面
- AI——人工智能,程序员的末路?
- 通过IP地址获取当前地理位置(省份)的接口
- Intel FFmpeg QSV安装
- java 同步锁(synchronized)