You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package issues.fastjson.myissue;
import java.util.Date;
import com.alibaba.fastjson.JSON;
/**
* @date 2020-03-04 09:22
**/
public class DateIssue {
public static void main(String[] args) {
try {
String json1 = "{\"date\":\"2019-11-1 21:45:12\"}";
MyObject myObject1 = JSON.parseObject(json1, MyObject.class);
System.out.println(myObject1.getDate());
} catch (Exception e) {
e.printStackTrace();
}
try {
String json2 = "{\"date\":\"2019-11-01 21:45:12\"}";
MyObject myObject2 = JSON.parseObject(json2, MyObject.class);
System.out.println(myObject2.getDate());
} catch (Exception e) {
e.printStackTrace();
}
}
public static class MyObject {
Date date;
public MyObject(Date date) {
this.date = date;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
}
这个是打印的信息
com.alibaba.fastjson.JSONException: For input string: "2019-11-1 21:45:12"
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:692)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:383)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:287)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:560)
at issues.fastjson.myissue.DateIssue.main(DateIssue.java:17)
Caused by: java.lang.NumberFormatException: For input string: "2019-11-1 21:45:12"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at com.alibaba.fastjson.serializer.DateCodec.cast(DateCodec.java:296)
at com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:177)
at com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:15)
at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:85)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.parseField(JavaBeanDeserializer.java:1241)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:866)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:288)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:685)
... 4 more
Fri Nov 01 21:45:12 CST 2019
The text was updated successfully, but these errors were encountered:
我测试了yyyy-M-dd和yyyy-M-d的情况是兼容的,但为什么yyyy-MM-d不兼容呢
![image](https://user-images.githubusercontent.com/21136213/75835907-28266200-5dfb-11ea-9031-6882384dfbae.png)
@wenshao
这个是打印的信息
com.alibaba.fastjson.JSONException: For input string: "2019-11-1 21:45:12"
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:692)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:383)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:287)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:560)
at issues.fastjson.myissue.DateIssue.main(DateIssue.java:17)
Caused by: java.lang.NumberFormatException: For input string: "2019-11-1 21:45:12"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at com.alibaba.fastjson.serializer.DateCodec.cast(DateCodec.java:296)
at com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:177)
at com.alibaba.fastjson.parser.deserializer.AbstractDateDeserializer.deserialze(AbstractDateDeserializer.java:15)
at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:85)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.parseField(JavaBeanDeserializer.java:1241)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:866)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:288)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:685)
... 4 more
Fri Nov 01 21:45:12 CST 2019
The text was updated successfully, but these errors were encountered: