解决FastJson 1.2.39的bug

前端之家收集整理的这篇文章主要介绍了解决FastJson 1.2.39的bug前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


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?'\'':'"';
}

猜你在找的Json相关文章