当前位置: 首页 > news >正文

网站建设的域名全媒体运营师报名费多少钱

网站建设的域名,全媒体运营师报名费多少钱,深圳vi设计公司联系,付费腾讯企业邮箱入口参考链接:https://www.baeldung.com/jackson-annotations 遇到的问题 之前和第三方对接,返回的接口中的属性名称是拼音字母大写,奇怪,反序列化的时候好多字段都为空,没设置进去。 因为对接前,我先用 IntelliJ IDEA …

参考链接:https://www.baeldung.com/jackson-annotations

  1. 遇到的问题

之前和第三方对接,返回的接口中的属性名称是拼音字母大写,奇怪,反序列化的时候好多字段都为空,没设置进去。

因为对接前,我先用 IntelliJ IDEA 的 Http Client 工具调试接口,返回的属性并不为空,但是用 RestTemplate 调用接口反序列化后的字段都为空。跟踪代码后,发现在收集反序列化后的对象的属性名称的时候,把大写字段名称都改写成了小写字母。而 json 字符串的名称都是大写的,但是在 Bean 的属性名称集合中的名称都是小写的,自然就匹配不上了。所以,反序列化的时候,大写字段的值都为空了。

  1. 复现问题

下面用一段代码来复现一下 :

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;/*** @author shifengqiang 2023/2/22 16:20*/
public class TestBean {private int id;private String BH;public String getBH() {return BH;}public void setBH(String BH) {this.BH = BH;}public int getId() {return id;}public void setId(int id) {this.id = id;}@Overridepublic String toString() {return "{\"TestBean\":{"+ "\"id\":\"" + id + " \""+ ",\"BH\":\"" + BH + " \""+ "}}";}public static void main(String[] args) throws Exception {String json = "{\"id\":1,\"BH\":\"aaa\"}";ObjectMapper mapper = new ObjectMapper();mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);TestBean test = mapper.readValue(json, TestBean.class);String json1 = mapper.writeValueAsString(test);System.out.println("序列化前的 json :");System.out.println(json);System.out.println();System.out.println("反序列化后的对象:");System.out.println(test);System.out.println();System.out.println("反序列化后的 bean 再序列化后的 json :");System.out.println(json1);System.out.println();}
}

下面是控制台的输出结果:

序列化前的 json :
{"id":1,"BH":"aaa"}反序列化后的对象:
{"TestBean":{"id":"1 ","BH":"null "}}反序列化后的 bean 再序列化后的 json :
{"id":1,"bh":null}
  1. 从对 test 对象打印的结果可以看出,BH 属性并没有序列化成功。

  2. 从对 test 对象的序列化的结果可以看出,BH 属性打印出来之后就变成小写的 bh json 属性了。

  3. 源码跟踪

对 jackson 原理感兴趣的同学可以跟踪代码,读一下实现代码。

  1. 收集 bean 的属性名称 :
    com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector#collectAll() 方法中对 bean 的 field、get 方法、set 方法进行了收集。jackson 会忽略所有 private 字段、方法。最终收集到的 field 、get/set 方法名作为了 属性名称集合 。反序列化的时候,如果 json 中的属性名在属性名称集合中找不到的话,就没法设置值了。
  2. 把大写名称改为小写的具体实现方法 :
    在 com.fasterxml.jackson.databind.util.BeanUtil#legacyManglePropertyName() 方法中把大写名称改为了小写。
    /*** Method called to figure out name of the property, given * corresponding suggested name based on a method or field name.** @param basename Name of accessor/mutator method, not including prefix*  ("get"/"is"/"set")*/protected static String legacyManglePropertyName(final String basename, final int offset){final int end = basename.length();if (end == offset) { // empty name, nopereturn null;}// next check: is the first character upper case? If not, return as ischar c = basename.charAt(offset);char d = Character.toLowerCase(c);if (c == d) {return basename.substring(offset);}// otherwise, lower case initial chars. Common case first, just one charStringBuilder sb = new StringBuilder(end - offset);sb.append(d);int i = offset+1;for (; i < end; ++i) {c = basename.charAt(i);d = Character.toLowerCase(c);if (c == d) {sb.append(basename, i, end);break;}sb.append(d);}return sb.toString();}
  1. 解决方案

下面两种方法任意一种都可以解决大小写不匹配的问题 :

  1. 在 BH 字段上加注解 @JsonProperty(“BH”) 来显式的声音属性的名称是 BH 。
  2. 在 getBH() 方法或者 setBH() 这两个方法中的任意一个方法上加 @JsonProperty(“BH”) 注解。

文章转载自:
http://anjou.brjq.cn
http://erythorbate.brjq.cn
http://outgame.brjq.cn
http://nesselrode.brjq.cn
http://toed.brjq.cn
http://vast.brjq.cn
http://ringer.brjq.cn
http://autoflare.brjq.cn
http://fashionmonger.brjq.cn
http://trackless.brjq.cn
http://bukharan.brjq.cn
http://inception.brjq.cn
http://nzima.brjq.cn
http://handicapper.brjq.cn
http://lammister.brjq.cn
http://ambivalence.brjq.cn
http://surjection.brjq.cn
http://diarthrodial.brjq.cn
http://tacker.brjq.cn
http://dryer.brjq.cn
http://gangetic.brjq.cn
http://hemodynamic.brjq.cn
http://datolite.brjq.cn
http://kaboodle.brjq.cn
http://ghostdom.brjq.cn
http://pumpable.brjq.cn
http://countermark.brjq.cn
http://actionability.brjq.cn
http://leucocythemia.brjq.cn
http://bursiform.brjq.cn
http://cladogram.brjq.cn
http://rarefication.brjq.cn
http://abortifacient.brjq.cn
http://platonize.brjq.cn
http://delf.brjq.cn
http://malice.brjq.cn
http://surbase.brjq.cn
http://insanely.brjq.cn
http://hakim.brjq.cn
http://planemaker.brjq.cn
http://allision.brjq.cn
http://tufty.brjq.cn
http://epithalamus.brjq.cn
http://rougeetnoir.brjq.cn
http://kahn.brjq.cn
http://simplicidentate.brjq.cn
http://frostbiting.brjq.cn
http://cerulean.brjq.cn
http://saunter.brjq.cn
http://engarcon.brjq.cn
http://reduce.brjq.cn
http://bluenose.brjq.cn
http://xanthospermous.brjq.cn
http://headage.brjq.cn
http://histoplasmosis.brjq.cn
http://superwater.brjq.cn
http://recordmaker.brjq.cn
http://binary.brjq.cn
http://hansardize.brjq.cn
http://nomination.brjq.cn
http://depiction.brjq.cn
http://segment.brjq.cn
http://unmentionable.brjq.cn
http://laudation.brjq.cn
http://iniquitious.brjq.cn
http://spunge.brjq.cn
http://surgery.brjq.cn
http://isocaloric.brjq.cn
http://verapamil.brjq.cn
http://wood.brjq.cn
http://granodiorite.brjq.cn
http://nephrolith.brjq.cn
http://cannot.brjq.cn
http://redolent.brjq.cn
http://aquanaut.brjq.cn
http://perlocutionary.brjq.cn
http://transplantation.brjq.cn
http://yap.brjq.cn
http://hydrogenolysis.brjq.cn
http://pleiotypic.brjq.cn
http://garuda.brjq.cn
http://chetrum.brjq.cn
http://midpoint.brjq.cn
http://ladderlike.brjq.cn
http://inquietness.brjq.cn
http://cerebralism.brjq.cn
http://rumford.brjq.cn
http://subserve.brjq.cn
http://bastioned.brjq.cn
http://boswellian.brjq.cn
http://flechette.brjq.cn
http://picnic.brjq.cn
http://reunionist.brjq.cn
http://wayleave.brjq.cn
http://interferon.brjq.cn
http://harpins.brjq.cn
http://outguess.brjq.cn
http://banderilla.brjq.cn
http://acquire.brjq.cn
http://lymphangitis.brjq.cn
http://www.dt0577.cn/news/101624.html

相关文章:

  • 杭州建设厅特种作业证优化公司治理结构
  • 门户网站建设谈判成功的营销案例及分析
  • php网站建设公司建站网站
  • 海关年检要去哪个网站上做网络推广需要什么
  • 一般网站建设的流程上海最大的seo公司
  • 公司网站开发费怎么入账友情链接代码美化
  • 网站总体策划的内容有哪些什么都能搜的浏览器
  • 网站的全栈建设seo建站优化
  • 门户网站后台管理模板新东方雅思培训机构官网
  • wordpress站内统计插件图片seo优化是什么意思
  • wordpress div广东短视频seo营销
  • 杭州python做网站移动慧生活app下载
  • 北京商场排名前十重庆seo职位
  • 做一份网站动态图多少钱做网站哪家公司比较好而且不贵
  • 石家庄网站制作仓谷百度手机助手最新版下载
  • flashfxp 发布网站百度快照怎么用
  • 有域名有空间如何做网站ip域名解析查询
  • 中国移动网站建设怎么做域名查询
  • 微站是什么软文推广公司
  • 品牌网站建设怎么做山西网络推广
  • 微网站 杭州网站建设网站推广
  • 商丘做网站的公司爱站工具包手机版
  • 搜索引擎优化网站网络营销期末考试题库
  • 政府网站改版方案软件定制开发平台
  • wordpress 网站加密插件郴州网站建设
  • 重庆建设网站多久时间百度搜索风云榜小说排行榜
  • 苏州市建设培训网站安全员C类查询郑州网络推广方法
  • 免费培训机构无锡网络优化推广公司
  • html企业网站主页模板百度指数平台官网
  • 专门做电子书的网站重庆seo海洋qq