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

JSON.parseObject 多次执行结果不一样 #497

Closed
chocotan opened this Issue Feb 3, 2016 · 6 comments

Comments

Projects
None yet
5 participants
@chocotan
Copy link

chocotan commented Feb 3, 2016

<dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.4</version>
</dependency>
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import java.util.Date;

public class TestBean {
    private String taskId;
    private String taskName;
    private Long taskStatus;

    @JSONField(serialize = false, deserialize = true)
    private Date taskCreateTime;
    @JSONField(name = "taskCreateTime", serialize = true, deserialize = false)
    private String taskCreateTimeStr;

    @JSONField(serialize = false, deserialize = true)
    private Date timeout;
    @JSONField(name = "timeout", serialize = true, deserialize = false)
    private String timeoutStr;

    private String features;

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public Long getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(Long taskStatus) {
        this.taskStatus = taskStatus;
    }

    public void setTaskCreateTime(Date taskCreateTime) {
        this.taskCreateTime = taskCreateTime;
    }

    public Date getTaskCreateTime() {
        return taskCreateTime;
    }

    public Date getTimeout() {
        return timeout;
    }

    public void setTimeout(Date timeout) {
        this.timeout = timeout;
    }

    public String getFeatures() {
        return features;
    }

    public void setFeatures(String features) {
        this.features = features;
    }

    public String getTaskCreateTimeStr() {
        return taskCreateTimeStr;
    }

    public void setTaskCreateTimeStr(String taskCreateTimeStr) {
        this.taskCreateTimeStr = taskCreateTimeStr;
    }

    public String getTimeoutStr() {
        return timeoutStr;
    }

    public void setTimeoutStr(String timeoutStr) {
        this.timeoutStr = timeoutStr;
    }


    public static void main(String[] args) {
        String str = "{\"taskCreateTime\":\"2016-02-03 16:03:14\",\"taskId\":\"5102840\",\"taskName\":\"CP处理工单\",\"taskStatus\":\"1\",\"timeout\":\"2016-03-04 16:03:14\"}";
        TestBean t = JSON.parseObject(str, TestBean.class);
        System.out.println("taskCreateTime:" + t.getTaskCreateTime());
        System.out.println("taskCreateTimeStr:" + t.getTaskCreateTimeStr());
        System.out.println("timeout:" + t.getTimeout());
        System.out.println("timeoutStr:" + t.getTimeoutStr());
    }
}

多次运行如下:

第一次

taskCreateTime:null
taskCreateTimeStr:2016-02-03 16:03:14
timeout:null
timeoutStr:2016-03-04 16:03:14

第二次

taskCreateTime:Wed Feb 03 16:03:14 CST 2016
taskCreateTimeStr:null
timeout:null
timeoutStr:2016-03-04 16:03:14

第三次

taskCreateTime:null
taskCreateTimeStr:2016-02-03 16:03:14
timeout:null
timeoutStr:2016-03-04 16:03:14

第四次

taskCreateTime:null
taskCreateTimeStr:2016-02-03 16:03:14
timeout:Fri Mar 04 16:03:14 CST 2016
timeoutStr:null
@cmonkey

This comment has been minimized.

Copy link

cmonkey commented Mar 1, 2016

我刚才搜索spring cloud 的时候,到你blog 上了
我发现在我本地fastjson 1.2.4 / 1.2.7都没有发现这个问题
我使用的jdk version = 1.8.0_60

@chocotan

This comment has been minimized.

Copy link

chocotan commented Mar 1, 2016

嗯奇怪我自己电脑上也没问题.....明天上班了我再验证一下..... : (

spring-cloud资料很少啊

2016-03-01 21:38 GMT+08:00 cmonkey notifications@github.com:

我刚才搜索spring cloud 的时候,到你blog 上了
我发现在我本地fastjson 1.2.4 / 1.2.7都没有发现这个问题
我使用的jdk version = 1.8.0_60


Reply to this email directly or view it on GitHub
#497 (comment).

@chocotan

This comment has been minimized.

Copy link

chocotan commented Mar 2, 2016

还是有问题,
windows 10 ,java版本如图
image

@CodePlayer

This comment has been minimized.

Copy link
Contributor

CodePlayer commented Mar 10, 2016

我本地测试也没发现你所说的问题。fastjson:1.2.9-SNAPSHOT,Java:1.8.0_73。
第一次:

taskCreateTime:Wed Feb 03 16:03:14 GMT+08:00 2016
taskCreateTimeStr:null
timeout:Fri Mar 04 16:03:14 GMT+08:00 2016
timeoutStr:null

第二次:

taskCreateTime:Wed Feb 03 16:03:14 GMT+08:00 2016
taskCreateTimeStr:null
timeout:Fri Mar 04 16:03:14 GMT+08:00 2016
timeoutStr:null

第三次:

taskCreateTime:Wed Feb 03 16:03:14 GMT+08:00 2016
taskCreateTimeStr:null
timeout:Fri Mar 04 16:03:14 GMT+08:00 2016
timeoutStr:null
@yrom

This comment has been minimized.

Copy link

yrom commented Mar 11, 2016

@JSONField(name = "taskCreateTime", serialize = true, deserialize = false)
private String taskCreateTimeStr;

我猜问题出在这里name = "taskCreateTime"

@wenshao wenshao added this to the 1.2.9 milestone Apr 8, 2016

@wenshao

This comment has been minimized.

Copy link
Member

wenshao commented Apr 8, 2016

已经修复,等新版本1.2.9发布吧

@wenshao wenshao closed this Apr 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment