Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

纳秒级 Timestamp 解析异常 #2894

Closed
SELiOTe opened this issue Nov 20, 2019 · 1 comment
Closed

纳秒级 Timestamp 解析异常 #2894

SELiOTe opened this issue Nov 20, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@SELiOTe
Copy link

SELiOTe commented Nov 20, 2019

package com.seliote.demo;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.sql.Timestamp;
import java.time.LocalDateTime;

public class FastJsonTest {
    public static void main(String... args) {
        String json = "{\"timestamp\": \"2019-09-19 08:49:52.350000000\", " +
                "\"local_date_time\": \"2019-09-19 08:49:52.350000000\"}";
        Pojo pojo = JSONObject.parseObject(json, Pojo.class);
    }
}

@Data
class Pojo {
    // 不正确,解析出是 2019-09-23 10:03:12.0
    @JSONField(name = "timestamp", format = "yyyy-MM-dd HH:mm:ss.SSSSSSSSS")
    private Timestamp timestamp;
    // 正确,解析出是 2019-09-19T08:49:52.350
    @JSONField(name = "local_date_time", format = "yyyy-MM-dd HH:mm:ss.SSSSSSSSS")
    private LocalDateTime localDateTime;
}
@vipcxj
Copy link

vipcxj commented Nov 21, 2019

以前遇到过类似的问题,jdk的dateformat好像默认没法处理纳秒的格式~ 估计fastjson用的就是jdk的api

@wenshao wenshao self-assigned this Nov 26, 2019
@wenshao wenshao added the bug label Nov 26, 2019
@wenshao wenshao added this to the 1.2.63 milestone Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants