alibaba / alibaba/fastjson2

[QUESTION]全局将LocalDateTime日期格式化

Open
#1,702 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 请描述您的问题
*通过Spring消息转换器,需要全局将LocalDateTime类型的日志格式化为:2023-07-31T05:38:39.026Z*
目前是没有T Z的,用的是好早之前wenshao给的一个方案:

// 自定义LocalTime序列化格式
JSON.register(LocalDateTime.class, (jsonWriter, object, fieldName, fieldType, features) -> {
if (object == null) {
jsonWriter.writeNull();
return;
}
LocalDateTime localTime = (LocalDateTime) object;
jsonWriter.writeString(localTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
});

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the Spring message converter context and the provided LocalDateTime serializer registration. No source file, test, or specific change is named in the issue, so first determine where global date-time formatting is configured and what behavior should be verified for the requested UTC-style output.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.