Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved java.time.Instan & org.joda.time.Instant support. fix #3539
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
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
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
46 changes: 46 additions & 0 deletions
46
src/test/java/com/alibaba/json/bvt/issue_3500/Issue3539.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,46 @@ | ||
package com.alibaba.json.bvt.issue_3500; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import junit.framework.TestCase; | ||
|
||
import java.time.Instant; | ||
|
||
public class Issue3539 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
String str = "{\"date\":{\"nano\":140000000,\"epochSecond\":1605106869}}"; | ||
Bean bean = JSON.parseObject(str, Bean.class); | ||
assertNotNull(bean.date); | ||
JSON.toJSONString(bean); | ||
|
||
JSON.parseObject(str) | ||
.toJavaObject(Bean.class); | ||
} | ||
|
||
public void test_for_issue_joda() throws Exception { | ||
String str = "{\"date\":{\"epochSecond\":1605106869}}"; | ||
JodaBean bean = JSON.parseObject(str, JodaBean.class); | ||
assertNotNull(bean.date); | ||
JSON.toJSONString(bean); | ||
|
||
JSON.parseObject(str) | ||
.toJavaObject(JodaBean.class); | ||
} | ||
|
||
public void test_for_issue_joda2() throws Exception { | ||
String str = "{\"date\":{\"millis\":1605364826724}}"; | ||
JodaBean bean = JSON.parseObject(str, JodaBean.class); | ||
assertNotNull(bean.date); | ||
JSON.toJSONString(bean); | ||
|
||
JSON.parseObject(str) | ||
.toJavaObject(JodaBean.class); | ||
} | ||
|
||
public static class Bean { | ||
public Instant date; | ||
} | ||
|
||
public static class JodaBean { | ||
public org.joda.time.Instant date; | ||
} | ||
} |