-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LocalDateTime & LocalDate parse support more cases
- Loading branch information
Showing
4 changed files
with
120 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
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
54 changes: 54 additions & 0 deletions
54
core/src/test/java/com/alibaba/fastjson2/issues_2800/Issue2859.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,54 @@ | ||
package com.alibaba.fastjson2.issues_2800; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2859 { | ||
@Test | ||
public void test() { | ||
String str = "{\"time\":\"-999999999-11-12 13:14:15\"}"; | ||
{ | ||
Bean bean = JSON.parseObject(str, Bean.class); | ||
assertEquals(str, JSON.toJSONString(bean)); | ||
} | ||
{ | ||
Bean bean = JSON.parseObject(str.getBytes(StandardCharsets.UTF_8), Bean.class); | ||
assertEquals(str, JSON.toJSONString(bean)); | ||
} | ||
{ | ||
Bean bean = JSON.parseObject(str.toCharArray(), Bean.class); | ||
assertEquals(str, JSON.toJSONString(bean)); | ||
} | ||
} | ||
|
||
static class Bean { | ||
public LocalDateTime time; | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
String str = "{\"date\":\"-999999999-11-12\"}"; | ||
{ | ||
Bean1 bean = JSON.parseObject(str, Bean1.class); | ||
assertEquals(str, JSON.toJSONString(bean)); | ||
} | ||
{ | ||
Bean1 bean = JSON.parseObject(str.getBytes(StandardCharsets.UTF_8), Bean1.class); | ||
assertEquals(str, JSON.toJSONString(bean)); | ||
} | ||
{ | ||
Bean1 bean = JSON.parseObject(str.toCharArray(), Bean1.class); | ||
assertEquals(str, JSON.toJSONString(bean)); | ||
} | ||
} | ||
|
||
static class Bean1 { | ||
public LocalDate date; | ||
} | ||
} |