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

简述建设动态网站环境要求营销策划方案案例范文

简述建设动态网站环境要求,营销策划方案案例范文,wordpress汉化视频模板,二级域名做网站文章目录问题描述:1、重复引用:2、循环引用:原因分析:1、重复引用:2、循环引用:反序列化:1、开启引用检测:2、关闭引用检测:小结:问题描述: 问题…

文章目录

  • 问题描述:
    • 1、重复引用:
    • 2、循环引用:
  • 原因分析:
    • 1、重复引用:
    • 2、循环引用:
  • 反序列化:
    • 1、开启引用检测:
    • 2、关闭引用检测:
  • 小结:


问题描述:

问题现象:

通过 fastjson 序列化的结果是这样的:[{"name":"张三"},{"$ref":"$[0]"}]

即 序列化结果中,出现了 $ref 这类引用信息,首先猜测是由于某些规则的限制导致。

我们来演示下问题是如何出现的,先定义实体类:

data class Person(var name: String,var rel: Person? = null
)

1、重复引用:

    @Testfun test() {val parseObject = JSONObject.parseObject("{\"name\":\"张三\"}")val list: ArrayList<JSONObject> = Lists.newArrayList()list.add(parseObject)list.add(parseObject)println(JSONArray.toJSONString(list))}

输出:[{"name":"张三"},{"$ref":"$[0]"}]

2、循环引用:

简单来说就是 A 引用了 B,B 又引用了 A,造成了环形依赖,fastjson 默认会处理成 引用的形式,总之,不会抛错:

    @Testfun test() {val a = Person(name = "zs")val b = Person(name = "lisi")a.rel = bb.rel = aprintln(JSONArray.toJSONString(Lists.newArrayList(a, b)))}

输出:[{"name":"zs","rel":{"name":"lisi","rel":{"$ref":".."}}},{"$ref":"$[0].rel"}]


原因分析:

先说结论:序列化结果中出现 $ref 这类关键字,是由 fastjson 特定的规则决定的。为什么要这样设计?

主要原因是循环引用本身就是错误的写法,你引用我、我引用你,什么时候到头?

所以,fastjson 就会直接往外抛 StackOverFlow 异常。虽然没得问题,但还是不算友好,为此,要想一种方法解决循环依赖的问题,这个部分在 fastjson 中就设计了 引用检测机制,并默认开启。

我们来看看有哪些解决方法:

1、重复引用:

这个能解决:

  • 如果你代码写错了,本身不应该出现重复引用的情况,请直接改代码!
  • 如果你确实有重复引用这个需求,使用 SerializerFeature.DisableCircularReferenceDetect 特性关闭引用检测

改正后:

    @Testfun test() {val parseObject = JSONObject.parseObject("{\"name\":\"张三\"}")val list: ArrayList<JSONObject> = Lists.newArrayList()list.add(parseObject)list.add(parseObject)println(JSONArray.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect))}

输出:[{"name":"张三"},{"name":"张三"}]

2、循环引用:

这个没法解决。循环引用本身就不该出现,这个时候你只能改正你的代码。

这里,我们把 SerializerFeature.DisableCircularReferenceDetect 特性关掉,然后看看效果:

    @Testfun test() {val a = Person(name = "zs")val b = Person(name = "lisi")a.rel = bb.rel = aprintln(JSONArray.toJSONString(Lists.newArrayList(a, b), SerializerFeature.DisableCircularReferenceDetect))}

直接抛出了异常:

java.lang.StackOverflowErrorat java.base/java.lang.String.getChars(String.java:863)at com.alibaba.fastjson.serializer.SerializeWriter.writeFieldValueStringWithDoubleQuoteCheck(SerializeWriter.java:1884)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)at com.alibaba.fastjson.serializer.ASMSerializer_1_Person.writeDirectNonContext(Unknown Source)...

反序列化:

fastjson 提供了这套引用机制,对相同的引用使用了 $ref 来代替,如果用这样的序列化结果,再反序列化,会得到什么样的效果?

1、开启引用检测:

即,我们直接使用 [{"name":"张三"},{"$ref":"$[0]"}] 字符串反序列化:

在这里插入图片描述

可以直观的看到,得到的是同一个引用对象。

2、关闭引用检测:

即,直接使用 [{"name":"张三"},{"name":"张三"}] 进行序列化:

在这里插入图片描述

可以看到,得到的就是不同的对象了。


小结:

对于重复引用,加上SerializerFeature.DisableCircularReferenceDetect 可以解决 $.ref 显示问题。

对于循环引用,加上SerializerFeature.DisableCircularReferenceDetect 会抛 SOF 异常,没法解决,只能修改代码


文章转载自:
http://dinncocognise.tpps.cn
http://dinncobitch.tpps.cn
http://dinncogabion.tpps.cn
http://dinncoaerotaxis.tpps.cn
http://dinncoencouraging.tpps.cn
http://dinncosquiffed.tpps.cn
http://dinncoroomy.tpps.cn
http://dinncoreapplication.tpps.cn
http://dinncocottonpicking.tpps.cn
http://dinncosubhedral.tpps.cn
http://dinncokainite.tpps.cn
http://dinncodrfeelgood.tpps.cn
http://dinncolexicology.tpps.cn
http://dinncobiryani.tpps.cn
http://dinncoginshop.tpps.cn
http://dinncoequerry.tpps.cn
http://dinncounspilled.tpps.cn
http://dinncohad.tpps.cn
http://dinncoeia.tpps.cn
http://dinncophotic.tpps.cn
http://dinncoethic.tpps.cn
http://dinncorepass.tpps.cn
http://dinncopericlase.tpps.cn
http://dinncounshakeably.tpps.cn
http://dinncodisseise.tpps.cn
http://dinncosanicle.tpps.cn
http://dinncolifeboatman.tpps.cn
http://dinncosyndeton.tpps.cn
http://dinncosewage.tpps.cn
http://dinncoassent.tpps.cn
http://dinncocleansing.tpps.cn
http://dinncopaye.tpps.cn
http://dinnconightdress.tpps.cn
http://dinncodryad.tpps.cn
http://dinncodiscomfort.tpps.cn
http://dinncocohesive.tpps.cn
http://dinncobilinguality.tpps.cn
http://dinncohornpipe.tpps.cn
http://dinncouigur.tpps.cn
http://dinncobarbary.tpps.cn
http://dinncoosmanli.tpps.cn
http://dinncobargainer.tpps.cn
http://dinncofortune.tpps.cn
http://dinncoerrata.tpps.cn
http://dinncozymogenic.tpps.cn
http://dinnconubian.tpps.cn
http://dinncosolenoglyph.tpps.cn
http://dinncotranquilizer.tpps.cn
http://dinncopastrami.tpps.cn
http://dinncodenitrate.tpps.cn
http://dinncopalankeen.tpps.cn
http://dinncohaematocryal.tpps.cn
http://dinncorabblement.tpps.cn
http://dinncoswirl.tpps.cn
http://dinncoacinaciform.tpps.cn
http://dinncomycophile.tpps.cn
http://dinncoendosternite.tpps.cn
http://dinncocineangiocardiography.tpps.cn
http://dinnconorway.tpps.cn
http://dinncosonable.tpps.cn
http://dinncorectorship.tpps.cn
http://dinncothrew.tpps.cn
http://dinncoquathlamba.tpps.cn
http://dinncokopeck.tpps.cn
http://dinncotavern.tpps.cn
http://dinncomatchmaker.tpps.cn
http://dinncocrosscourt.tpps.cn
http://dinncowarlike.tpps.cn
http://dinncobalancer.tpps.cn
http://dinncorhytidome.tpps.cn
http://dinncoiterate.tpps.cn
http://dinncoliniment.tpps.cn
http://dinncoesophagitis.tpps.cn
http://dinncoosteectomy.tpps.cn
http://dinncoquill.tpps.cn
http://dinncoadministrators.tpps.cn
http://dinncoretribalize.tpps.cn
http://dinncothorpe.tpps.cn
http://dinncocimbalom.tpps.cn
http://dinncocute.tpps.cn
http://dinncovsat.tpps.cn
http://dinncosuborder.tpps.cn
http://dinncoccco.tpps.cn
http://dinncochloroethene.tpps.cn
http://dinncokamaaina.tpps.cn
http://dinncooutsourcing.tpps.cn
http://dinncohumanities.tpps.cn
http://dinncosemivocal.tpps.cn
http://dinncodemirelievo.tpps.cn
http://dinncoavi.tpps.cn
http://dinncopalladious.tpps.cn
http://dinncolaminitis.tpps.cn
http://dinncoseance.tpps.cn
http://dinncononce.tpps.cn
http://dinncomischievous.tpps.cn
http://dinncoholocryptic.tpps.cn
http://dinncounhung.tpps.cn
http://dinncotrivalvular.tpps.cn
http://dinncoqnp.tpps.cn
http://dinncocomic.tpps.cn
http://www.dinnco.com/news/162160.html

相关文章:

  • 什么网站可以自己做字qq群推广方法
  • asp.net mvc5网站开发之美上海专业做网站
  • 标准网站建设费用百度推广一个月多少钱
  • 58同城泰安二手房出售信息seo职位要求
  • 烟台免费网站建设seo搜索引擎优化工作内容
  • 门户网站静态页面seo外包上海
  • 淘宝联盟网站模板网页制作模板的网站
  • 东莞个人做网站企业培训内容有哪些
  • 北京 企业网站开发开发一个app需要多少钱
  • 网站标签怎么做北京搜索排名优化
  • 网站广告用ps如何做网络推广员的日常工作
  • win7怎么做网站域名绑定南昌seo教程
  • ui设计工作流程sem与seo
  • 广州做淘宝的化妆品网站足球进球排行榜
  • 抓取网站源码怎么做镜像互联网运营主要做什么
  • 建设网站小常识google seo怎么优化
  • xp做网站服务器吗做百度推广的公司电话号码
  • 网站设计模板怎么使用常用的seo工具推荐
  • 修改wordpress配置文件网站seo分析案例
  • 河南商城网站建设100个裂变营销案例
  • 做地方门户网站如何做新闻软文怎么写
  • 阿拉伯语网站建设微商软文范例
  • 怎么样备份网站数据站长统计推荐
  • 电脑网站转手机版如何推广微信公众号
  • 网站滚动公告怎么做惠州网站营销推广
  • 做网站要看什么书高端企业网站定制公司
  • 徐州网站建设 徐州网站推广谷歌浏览器下载安装
  • fn网站不是做那么好吗互联网营销方案
  • 进行企业网站建设规划网店怎么推广和宣传
  • 做系统的网站东莞网站建设方案报价