分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

解决FastJson 1.2.39的bug

发布时间:2023-09-06 01:18责任编辑:赖小花关键词:暂无标签


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


com.alibaba.fastjson.serializer.JSONSerializer#writeWithFormat

修改后的代码:

public final void writeWithFormat(Object object, String format) {    if (object instanceof Date) {        DateFormat dateFormat = this.getDateFormat();        if(format!=null){            dateFormat = new SimpleDateFormat(format, locale);            dateFormat.setTimeZone(timeZone);        }        String text = dateFormat.format((Date) object);        out.writeString(text);        return;    }    write(object);}


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

com.alibaba.fastjson.serializer.SerializeWriter#computeFeatures

修改的代码:

    protected void computeFeatures() {        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 ? ‘\‘‘ : ‘"‘;    }


本文出自 “熔 ?岩” 博客,请务必保留此出处http://lavasoft.blog.51cto.com/62575/1973749

解决FastJson 1.2.39的bug

原文地址:http://lavasoft.blog.51cto.com/62575/1973749

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved