加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

解决FastJson 1.2.39的bug

发布时间:2020-12-16 19:01:39 所属栏目:百科 来源:网络整理
导读:1、日期转换默认格式覆盖注解格式的bug; com.alibaba.fastjson.serializer.JSONSerializer#writeWithFormat 修改后的代码: publicfinalvoidwriteWithFormat(Objectobject,Stringformat){if(objectinstanceofDate){DateFormatdateFormat=this.getDateFormat


1、日期转换默认格式覆盖注解格式的bug;


com.alibaba.fastjson.serializer.JSONSerializer#writeWithFormat

修改后的代码:

publicfinalvoidwriteWithFormat(Objectobject,Stringformat){
if(objectinstanceofDate){
DateFormatdateFormat=this.getDateFormat();
if(format!=null){
dateFormat=newSimpleDateFormat(format,locale);
dateFormat.setTimeZone(timeZone);
}
Stringtext=dateFormat.format((Date)object);
out.writeString(text);
return;
}
write(object);
}


2、解决转JSON时候Bean字段默认被排序的毛病:

com.alibaba.fastjson.serializer.SerializeWriter#computeFeatures

修改的代码:

protectedvoidcomputeFeatures(){
quoteFieldNames=(this.features&SerializerFeature.QuoteFieldNames.mask)!=0;
useSingleQuotes=(this.features&SerializerFeature.UseSingleQuotes.mask)!=0;
//sortField=(this.features&SerializerFeature.SortField.mask)!=0;
sortField=false;
disableCircularReferenceDetect=(this.features&SerializerFeature.DisableCircularReferenceDetect.mask)!=0;
beanToArray=(this.features&SerializerFeature.BeanToArray.mask)!=0;
writeNonStringValueAsString=(this.features&SerializerFeature.WriteNonStringValueAsString.mask)!=0;
notWriteDefaultValue=(this.features&SerializerFeature.NotWriteDefaultValue.mask)!=0;
writeEnumUsingName=(this.features&SerializerFeature.WriteEnumUsingName.mask)!=0;
writeEnumUsingToString=(this.features&SerializerFeature.WriteEnumUsingToString.mask)!=0;

writeDirect=quoteFieldNames//
&&(this.features&nonDirectFeautres)==0//
&&(beanToArray||writeEnumUsingName)
;

keySeperator=useSingleQuotes?''':'"';
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读