com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "FileSize"
请求阿里云的OSS接口图片信息,返回json格式的数据,通过ObjectMapper将json转为Image对象时候报错转换失败
将json转对象的代码:
String jsonStr = "{\n" +
" \"FileSize\": {\"value\": \"25929\"},\n" +
" \"Format\": {\"value\": \"jpg\"},\n" +
" \"ImageHeight\": {\"value\": \"200\"},\n" +
" \"ImageWidth\": {\"value\": \"300\"},\n" +
" \"ResolutionUnit\": {\"value\": \"1\"},\n" +
" \"XResolution\": {\"value\": \"100/1\"},\n" +
" \"YResolution\": {\"value\": \"100/1\"}}";
ObjectMapper objectMapper = new ObjectMapper();
Image image = objectMapper.readValue(jsonStr, Image.class);
报错信息:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "FileSize" (class com.xxx.xxx.bean.Image), not marked as ignorable (7 known properties: "resolutionUnit", "imageHeight", "xresolution", "yresolution", "format", "imageWidth", "fileSize"])
at [Source: {
"FileSize": {"value": "25929"},
"Format": {"value": "jpg"},
"ImageHeight": {"value": "200"},
"ImageWidth": {"value": "300"},
"ResolutionUnit": {"value": "1"},
"XResolution": {"value": "100/1"},
"YResolution": {"value": "100/1"}}; line: 2, column: 18] (through reference chain: com.xxx.xxx.bean.Image["FileSize"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1489)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1467)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858)
at com.xxx.xxx.service.PostOssService.main(OssService.java:103)
原因:
Image对象中缺少json的某个字段属性引起
解决:
1、加上如下两行代码:
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
2、在需要转化的对象的类中添加注解,注解信息如下:
@JsonIgnoreProperties(ignoreUnknown = true)
参考:
https://stackoverflow.com/questions/51034173/backblazetokenresponse-com-fasterxml-jackson-databind-exc-unrecognizedproperty
https://blog.csdn.net/qq_30739519/article/details/51273544
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "FileSize"的更多相关文章
- com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 异常
分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519) 1.1.1. 前言 近期在使用ObjectMapper对象将jso ...
- com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ExceptionId"
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Exception ...
- 16. nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "auditUnitName"
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver:handleHttpMessageNotRead ...
- Jackson反序列化错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field的解决方法
说明:出现这种问题的情况是由于JSON里面包含了实体没有的字段导致反序列化失败. 解决方法: // 第一种解决方案 // ObjectMapper对象添加 mapper.configure(Deser ...
- jackson json转实体对象 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
Jackson反序列化错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field的解 ...
- jackson json转实体 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
jackson 2.2.2 由于vo中缺少json的某个字段属性引起 2种解决方法 1:vo中添加注解@JsonIgnoreProperties(ignoreUnknown = true) 2. m ...
- JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc
代码程序: @PostMapping("selectById") @ResponseBody public Result selectById(@RequestBody int i ...
- com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class cn.edu.
详细信息 https://www.cnblogs.com/xuwenjin/p/8832522.html 解决办法: 在实体类上面加上注解 @JsonIgnoreProperties(value ...
- jackon - com.fasterxml.jackson.databind.exc.InvalidDefinitionException && UnrecognizedPropertyException: Unrecognized field 异常
在用jackson解析json数据是碰到的问题 1.首先是InvalidDefinitionException 测试发现可能是目标类中无无参数构造方法导致异常. 添加无参构造方法后发现前一个异常解决但 ...
随机推荐
- HDU 5302(Connect the Graph- 构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- JavaScript对象(复习笔记)
js对象 对象构造器 function person(firstname,lastname,age,eyecolor){ this.firstname=firstname; this.lastname ...
- nginx与apache 对比 apache是同步多进程模型,一个连接对应一个进程;nginx是异步的,多个连接(万级别)可以对应一个进程
nginx与apache详细性能对比 http://m.blog.csdn.net/lengzijian/article/details/7699444 http://www.cnblogs.com/ ...
- RK平台LCD调试说明【转】
本文转载自:http://blog.csdn.net/u014770862/article/details/76274951?locationNum=2&fps=1 RK平台LCD调试说明 原 ...
- 配置RabbitMQ远程访问
本文参考自:http://flashing.iteye.com/blog/1797531 1.如果远程客户端网络状况不是太好,比如adsl什么的,那么一定在客户端打开requstedHeartbeat ...
- 创建cell的三种方式
方式一 注册cell -> 无需为cell绑定标识符 [使用UIViewController完成!] l 1> static NSString * const ID = @"c ...
- Watir: 右键点击实例(某些如果应用AutoIt来做会更加简单高效)
require 'watir' module Watir class Element def top_edge assert_exists assert_enabled ole_object.getB ...
- Cortex-M3 / M4 Hard Fault Handler (转载)
转自大伟的,感谢大伟的帮助调试:http://www.cnblogs.com/shangdawei/archive/2013/04/30/3052491.html http://blog.frankv ...
- 01_创建一个新的activity&activity配置清单文件
今天开始学四大组件.今天是学Activity,然后是广播接收者,然后是服务,然后是内容提供者.四大组件,咱们一天一个.Activity就是跟用户交互的界面,大部分的应用都不会只有这么一个界面.创建多个 ...
- 超强XSS攻击利器
======================================================================= BackTrack 5 R1 XSS研究之XSSer(超 ...