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 测试发现可能是目标类中无无参数构造方法导致异常. 添加无参构造方法后发现前一个异常解决但 ...
随机推荐
- QC ALM 11创建域、项目和用户
一旦HP-ALM安装,我们仅仅能继续创建域.项目和用户使用后的ALM工作.以下是步骤来创建项目.域和用户. 一.创建域 1.对于创建域,第一步是进入站点管理员页面.开展QC使用URL - ...
- mac WebStorm 破解
摘要:因为想要学习HTML所以需要一个工具,同事推荐了webstorm.下载以后再网上搜破解方法.搜索到一个很简单的. 一.下载链接https://www.jetbrains.com/webstorm ...
- Vue常用语法及命令
1,Vue常用语法 vue常用语法之变量的定义 // 1,变量相关 // 变量的提升 var username = "雪雪"; var username ; console.log ...
- maximize_window fullscreen_window minimize_window
# Licensed to the Software Freedom Conservancy (SFC) under one# or more contributor license agreemen ...
- Oracle常用SQL与练习
基本 数学函数 rownum相关 分页查询 (假设每页显示10条) 不包含排序: 包含排序: 时间处理 1. to_char和to_date基本使用 eg1: eg2: 2)months_betwee ...
- codeforces 682C C. Alyona and the Tree(dfs)
题目链接: C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input ...
- 数据库sqlite3的使用-Navicat的安装
一:Navicat Navicat是一款著名的数据库管理软件,支持大部分主流数据库(包括SQLite) 1.Navicat的安装 (1)下载该软件后,先打开该软件 (2)把文件拖入到应用程序拷贝 (3 ...
- DOS命令汇总
汇总如下: Dos基础命令梳理思路 小编初来乍道, 不清楚我的插图在我发布后会不会不清晰, 因为我在排版时看到插入的图片是清晰的, 以前见其他条友发布的文章中总有不晰的图片, 很是不爽. 所以如果有不 ...
- hdu4888 Redraw Beautiful Drawings(最大流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4888 题意:给一个矩阵没行的和和每列的和,问能否还原矩阵,如果可以还原解是否唯一,若唯一输出该矩阵. ...
- POJ2823:Sliding Window
传送门 题意 有一个数列a,要求你求数列b和c,b[i]是a[i]-a[i+w-1]中的最小值,c[i]是最大值.如果a是1,3,-1,-3,5,3,6,7,则b为-1,-3,-3,-3,3,3,c为 ...