This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_331.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.alibaba.json.bvt.bug; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.JSONSerializer; | ||
import com.alibaba.fastjson.serializer.SerializeWriter; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class Bug_for_issue_331 extends TestCase { | ||
public void test_for_issue() 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); | ||
|
||
String json = JSON.toJSONString(original, SerializerFeature.UseISO8601DateFormat); | ||
|
||
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()); | ||
} | ||
|
||
public static class Model { | ||
private Date date; | ||
private Calendar calendar; | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(Date date) { | ||
this.date = date; | ||
} | ||
|
||
public Calendar getCalendar() { | ||
return calendar; | ||
} | ||
|
||
public void setCalendar(Calendar calendar) { | ||
this.calendar = calendar; | ||
} | ||
|
||
|
||
} | ||
} |