-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix support read java.sql.Date, for issue #2623
- Loading branch information
1 parent
8c59a01
commit c04070e
Showing
2 changed files
with
39 additions
and
0 deletions.
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
31 changes: 31 additions & 0 deletions
31
core/src/test/java/com/alibaba/fastjson2/issues_2600/Issue2623.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,31 @@ | ||
package com.alibaba.fastjson2.issues_2600; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONReader; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.TypeReference; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2623 { | ||
@Test | ||
public void test() { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("a", 1L); | ||
map.put("b", 2); | ||
map.put("c", 3F); | ||
map.put("d", new Date(System.currentTimeMillis())); | ||
map.put("e", new java.util.Date()); | ||
|
||
String s = JSON.toJSONString(map, JSONWriter.Feature.WriteClassName); | ||
Map<String, Object> map2 = JSON.parseObject(s, new TypeReference<Map<String, Object>>() { | ||
}, JSONReader.Feature.SupportAutoType); | ||
assertEquals(map.get("d").toString(), map2.get("d").toString()); | ||
assertEquals(map.get("e").toString(), map2.get("e").toString()); | ||
} | ||
} |