-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
V1.2.5 使用 ISO8601 序列化Calendar类型, 丢失时间数据 #331
Comments
请提供testcase |
@wenshao 测试用例: @Test
public void DateWithoutTimeTest() throws Exception
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse("2015-05-23");
Calendar c = Calendar.getInstance();
c.setTime(date);
Model original = new Model();
original.setDate(date);
original.setCalendar(c);
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.UseISO8601DateFormat, true);
serializer.write(original);
String json = out.toString();
System.out.println(json); //V1.2.4 输出{"calendar":"2015-05-23","date":"2015-05-23"} , V1.2.6 输出{"calendar":"2015-05-23+08:00","date":"2015-05-23+08:00"}
Model actual = JSON.parseObject(json, Model.class);
Assert.assertNotNull(actual);
Assert.assertNotNull(actual.getDate());
Assert.assertNotNull(actual.getCalendar());
Assert.assertEquals("与序列化前比较不相等", original.getDate(), actual.getDate());
Assert.assertEquals("序列化后的Date 和 Calendar 不相等", actual.getDate(), actual.getCalendar().getTime());
} 其中 Model 类型只有两个属性分别是Calendar 类型的 calendar 和 Date 类型的 date |
@wenshao 需要我提交一个单元测试的 request 吗? |
bug fixed. i will include in 1.2.9 & 1.1.49.android |
之前在 #301 中提到过 时区的问题在1.2.5已经解决了,但是又引入了新的问题:
Calendar 类型在只包含日期的场景序列化成 json 会是 yyyy-MM-dd+时区 这样的格式,丢失了 时间部分,不符合8601标准格式了.而且在浏览器生成 Date 对象也会出错,无法识别成日期格式.
请问这个问题应该如何解决?
The text was updated successfully, but these errors were encountered: