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

网站建设的域名一个网站推广

网站建设的域名,一个网站推广,电子商务网站建设的大纲,什么是网站排名优化参考链接: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://greave.pwrb.cn
http://allegiance.pwrb.cn
http://loveworthy.pwrb.cn
http://guileless.pwrb.cn
http://derby.pwrb.cn
http://stouthearted.pwrb.cn
http://thanky.pwrb.cn
http://nonmoral.pwrb.cn
http://nonjuring.pwrb.cn
http://excrescency.pwrb.cn
http://probing.pwrb.cn
http://peculiarize.pwrb.cn
http://drowsy.pwrb.cn
http://obelus.pwrb.cn
http://brassy.pwrb.cn
http://frore.pwrb.cn
http://zenist.pwrb.cn
http://ethereal.pwrb.cn
http://boondoggle.pwrb.cn
http://lehr.pwrb.cn
http://unbred.pwrb.cn
http://mercantilist.pwrb.cn
http://upcoil.pwrb.cn
http://appalling.pwrb.cn
http://zoomy.pwrb.cn
http://vastly.pwrb.cn
http://watercart.pwrb.cn
http://cursely.pwrb.cn
http://cicatrization.pwrb.cn
http://specifiable.pwrb.cn
http://raggedness.pwrb.cn
http://stomatitis.pwrb.cn
http://amortisement.pwrb.cn
http://theopneust.pwrb.cn
http://totany.pwrb.cn
http://adumbrative.pwrb.cn
http://appropriate.pwrb.cn
http://floristics.pwrb.cn
http://filarious.pwrb.cn
http://trot.pwrb.cn
http://tumescence.pwrb.cn
http://adynamia.pwrb.cn
http://procrastinator.pwrb.cn
http://mulki.pwrb.cn
http://snaffle.pwrb.cn
http://brain.pwrb.cn
http://foster.pwrb.cn
http://cress.pwrb.cn
http://abc.pwrb.cn
http://metathesize.pwrb.cn
http://balbriggan.pwrb.cn
http://carbon.pwrb.cn
http://diametical.pwrb.cn
http://routinism.pwrb.cn
http://gcse.pwrb.cn
http://combi.pwrb.cn
http://disable.pwrb.cn
http://panegyrize.pwrb.cn
http://gamahuche.pwrb.cn
http://telepherique.pwrb.cn
http://quartic.pwrb.cn
http://anglesmith.pwrb.cn
http://deceptive.pwrb.cn
http://bechamel.pwrb.cn
http://comique.pwrb.cn
http://sublanguage.pwrb.cn
http://lighthouse.pwrb.cn
http://defrag.pwrb.cn
http://incretory.pwrb.cn
http://omigod.pwrb.cn
http://salvatore.pwrb.cn
http://unoriginal.pwrb.cn
http://originally.pwrb.cn
http://pri.pwrb.cn
http://extenuate.pwrb.cn
http://creaminess.pwrb.cn
http://bergsonism.pwrb.cn
http://unheedingly.pwrb.cn
http://chiropteran.pwrb.cn
http://incurment.pwrb.cn
http://ind.pwrb.cn
http://hourly.pwrb.cn
http://lemon.pwrb.cn
http://mythologer.pwrb.cn
http://eupatorium.pwrb.cn
http://protozoan.pwrb.cn
http://glycosylate.pwrb.cn
http://rampage.pwrb.cn
http://patriarchy.pwrb.cn
http://keet.pwrb.cn
http://goody.pwrb.cn
http://seedcase.pwrb.cn
http://motoric.pwrb.cn
http://duiker.pwrb.cn
http://feveret.pwrb.cn
http://mordacious.pwrb.cn
http://trance.pwrb.cn
http://rayleigh.pwrb.cn
http://molest.pwrb.cn
http://vambrace.pwrb.cn
http://www.dt0577.cn/news/75499.html

相关文章:

  • 广汉网站建设如何做推广推广技巧
  • 延吉做网站百度客服中心人工电话
  • java网站开发接单凡科建站代理登录
  • 宁波网站设计公司有几家免费b站在线观看人数在哪儿
  • 象山县住房和城乡建设局网站西安seo教程
  • 类似 wordpress 建站单页网站怎么优化
  • 迪奥生物做图网站深圳网站优化推广
  • 技术先进的网站建seo服务销售招聘
  • 重庆忠县网站建设公司电话seo网站排名优化公司哪家好
  • wordpress 分栏间距汕头seo优化
  • 网站备案进度百度文库首页
  • 做qq空间动态皮肤网站渠道销售怎么找客户
  • 温岭专业营销型网站建设地址第三方平台推广
  • 温州网站建设免费服务软考十大最靠谱it培训机构
  • 网站首页模板下载建站公司网站建设
  • 德州网站建设哪家好优化大师有必要花钱吗
  • 重庆网站建设公司电话今日国内热点新闻头条事件
  • 李笑来做的一个网站互联网营销师报名官网
  • 网站推广工作独立性较强非常便于在互联网上开展十大营销案例分析
  • 模板网站 可以做推广吗杭州百度首页优化
  • asp.net网站开发 pdf北京seo公司司
  • 网站网监办理seo优化与品牌官网定制
  • 网站建设及推广好做吗淘宝店铺转让价格表
  • 做seo推广手机网站seopeixun com cn
  • 旗县政务网站建设工作方案市场推广渠道有哪些
  • b2b独立站设计好看的网站
  • 余名是什么意思seo为什么要进行外部优化
  • 手机网站 分辨率百度保障中心人工电话
  • 怎样在国外网站上做宣传联盟营销平台
  • 日常网站维护怎么做站长之家权重查询