fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] JSON.toJSONString on org.joda.time.DateTime

Open Cooperzzy opened this issue 1 year ago • 1 comments

问题描述

Based on #1605,Fastjson在反序列化org.joda.time.DateTime时不一致

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.49]

重现步骤

import com.alibaba.fastjson2.JSON;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1605Mutated_414 {
    @Test
    public void testMutated() {
        String s = "{\"dateTime\":\"2023-06-27T16:53:24.123Z\"}";
        BeanMutated bean = JSON.parseObject(s, BeanMutated.class);
        String s1 = JSON.toJSONString(bean);
        assertEquals("{\"dateTime\":\"2023-06-27T16:53:24.123Z\"}", s1);
    }

    @Test
    public void testMutatedfj() {
        String s = "{\"dateTime\":\"2023-06-27T16:53:24.123Z\"}";
        BeanMutated bean = com.alibaba.fastjson.JSON.parseObject(s, BeanMutated.class);
        String s1 = com.alibaba.fastjson.JSON.toJSONString(bean);
        assertEquals("{\"dateTime\":\"2023-06-27T16:53:24.123Z\"}", s1);
    }

    public static class BeanMutated {
        public DateTime getDateTime() {
            return dateTime;
        }

        public void setDateTime(DateTime dateTime) {
            this.dateTime = dateTime;
        }

        public DateTime dateTime;
    }

}

期待的正确结果

Fastjson 正确处理dateTime格式

相关日志输出

Expected :{"dateTime":"2023-06-27T16:53:24.123Z"} Actual :{"dateTime":1687884804123}

Cooperzzy avatar May 07 '24 17:05 Cooperzzy

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.50-SNAPSHOT/ 问题已修复,请帮忙用2.0.50-SNAPSHOT版本在你本地验证下

wenshao avatar May 08 '24 10:05 wenshao

经验证已修复,辛苦wenshao

Cooperzzy avatar May 10 '24 08:05 Cooperzzy

https://github.com/alibaba/fastjson2/releases/tag/2.0.50 2.0.50已发布,请用新版本

wenshao avatar May 12 '24 05:05 wenshao