Open yetoce opened 5 years ago
是否可以提供下测试用例的信息呢?
是否可以提供下测试用例的信息呢?
@Data
private static class JsonRequest {
@JSONField(name = "create_time", format = "yyyy-MM-dd")
private Date createTime;
}
@RequestMapping(value = "/json/v1", method = RequestMethod.GET)
public ResponseEntity<Object> json() {
String str = "{\"create_time\":\"1991-09-06\"}";
JsonRequest request = JSON.parseObject(str, JsonRequest.class);
return new ResponseEntity < > (RestResultUtil.success(), HttpStatus.OK);
}
以上这段代码测试,使用的fastjson 版本1.2.47,无其他任何fastjson配置
使用以下代码,并未复现你的现象:
public class Issue2383 {
public static void main(String[] args) {
String str1 = "{\"create_time\":\"1991-09-06\"}";
JsonRequest request1 = JSON.parseObject(str1, JsonRequest.class);
System.out.println(request1.createTime);
String str2 = "{\"create_time\":\"2019-09-06\"}";
JsonRequest request2 = JSON.parseObject(str2, JsonRequest.class);
System.out.println(request2.createTime);
}
public static class JsonRequest {
@JSONField(name = "create_time", format = "yyyy-MM-dd")
public Date createTime;
}
}
输出结果: Fri Sep 06 00:00:00 CST 1991 Fri Sep 06 00:00:00 CST 2019
当我使用1991-09-06来反序列化得到Date对象时,时间是CDT格式的,但是我用2019-09-06来反序列化,得到的时间就是CST格式的