Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix LocalDate use millis as default DateFormat, for issue #2477 Monster Yesterday 23:19 #2495

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

FullStackD
Copy link

What this PR does / why we need it?

Fixed the issue in the Fastjson v1 compatibility module where LocalDate deserialization defaulted to timestamp. This problem does not exist in both Fastjson1 and Fastjson2.

Summary of your change

Added the 'UseISO8601DateFormat' feature when generating the default DEFAULT_GENERATE_FEATURE. and wrote the corresponding test class. The default serialization of LocalDate, LocalDateTime, Instant, Date, LocalTime, OffsetDateTime, ZonedDateTime, and Calendar will all be affected.

Here are the date formats before the fix:

{
    "date": 1714329348277,
    "localDateTime": 1714329348277,
    "localTime": -19451723,
    "zonedDateTime": 1714329348277,
    "calendar": 1714329348277,
    "offsetDateTime": 1714329348277,
    "localDate": 1714320000000,
    "instant": 1714329348277
}

Here are the date formats after the fix:

{
    "date": "2024-04-29T02:36:33.686+08:00",
    "localDateTime": "2024-04-29T02:36:33.686+08:00",
    "localTime": "02:36:33.686",
    "zonedDateTime": "2024-04-29T02:36:33.687+08:00",
    "calendar": "2024-04-29T02:36:33.687+08:00",
    "offsetDateTime": "2024-04-29T02:36:33.686+08:00",
    "localDate": "2024-04-29",
    "instant": "2024-04-29T02:36:33.686+08:00"
}

@CLAassistant
Copy link

CLAassistant commented Apr 28, 2024

CLA assistant check
All committers have signed the CLA.

@wenshao
Copy link
Member

wenshao commented May 1, 2024

请在本地执行mvn validate修复codestyle问题,通过mvn clean install跑通过testcase

@FullStackD
Copy link
Author

@wenshao 我有个疑问,我又重新看了下代码发现Date的默认序列化在fastjson2中变成了writeDateTimeISO8601,而在fastjson1中是时间戳,这个新的feature吗?

@wenshao
Copy link
Member

wenshao commented May 3, 2024

是的,fastjson2序列化Date的行为缺省是yyyy-MM-dd'T'HH:mm:ss[.SSS]了,因为millis的方式大家反馈不方便。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants