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

纳秒级 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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants