alibaba / alibaba/fastjson2

[FEATURE]关于getDate 方法调用

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

Description

当json中的时间字段为10位时间戳的时候 new Date 的api无法正确的转换时间

public Date getDate(String key) {
Object value = super.get(key);

if (value == null) {
return null;
}

if (value instanceof Date) {
return (Date) value;
}

if (value instanceof String) {
return DateUtils.parseDate((String) value);
}

if (value instanceof Number) {
long millis = ((Number) value).longValue();
return new Date(millis);
}

return TypeUtils.toDate(value);
}
可以在
if (value instanceof Number) {
long millis = ((Number) value).longValue();
return new Date(millis);
} 这部分增加一个关于时间戳长度的判断

Contributor guide

Open the contributing guide

Research direction

Start at the getDate(String key) entry point and inspect the Number branch shown in the issue. Reproduce conversion of a JSON timestamp with 10 digits, then define the length-based handling so the resulting Date represents the intended time; verify both timestamp-length cases after the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.