-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
date deserialize support input empty string, for issue #467
- Loading branch information
Showing
10 changed files
with
189 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
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
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
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
145 changes: 145 additions & 0 deletions
145
core/src/test/java/com/alibaba/fastjson2/issues/Issue467.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,145 @@ | ||
package com.alibaba.fastjson2.issues; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.*; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class Issue467 { | ||
@Test | ||
public void test() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean.class).date); | ||
} | ||
|
||
public static class Bean { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public Date date; | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean1.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean1.class).date); | ||
} | ||
|
||
public static class Bean1 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public Calendar date; | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean2.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean2.class).date); | ||
} | ||
|
||
public static class Bean2 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public Instant date; | ||
} | ||
|
||
@Test | ||
public void test3() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean3.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean3.class).date); | ||
} | ||
|
||
public static class Bean3 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public LocalDateTime date; | ||
} | ||
|
||
@Test | ||
public void test4() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean4.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean4.class).date); | ||
} | ||
|
||
public static class Bean4 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public LocalDate date; | ||
} | ||
|
||
@Test | ||
public void test5() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean5.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean5.class).date); | ||
} | ||
|
||
public static class Bean5 { | ||
@JSONField(format = "HH:mm:ss") | ||
public LocalTime date; | ||
} | ||
|
||
@Test | ||
public void test6() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean6.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean6.class).date); | ||
} | ||
|
||
public static class Bean6 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public java.sql.Date date; | ||
} | ||
|
||
@Test | ||
public void test7() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean7.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean7.class).date); | ||
} | ||
|
||
public static class Bean7 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public java.sql.Timestamp date; | ||
} | ||
|
||
@Test | ||
public void test8() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean8.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean8.class).date); | ||
} | ||
|
||
public static class Bean8 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public java.sql.Time date; | ||
} | ||
|
||
@Test | ||
public void test9() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean9.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean9.class).date); | ||
} | ||
|
||
public static class Bean9 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public org.joda.time.LocalDate date; | ||
} | ||
|
||
@Test | ||
public void test10() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean10.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean10.class).date); | ||
} | ||
|
||
public static class Bean10 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public org.joda.time.LocalDateTime date; | ||
} | ||
|
||
@Test | ||
public void test11() { | ||
assertNull(JSON.parseObject("{\"date\":\"\"}", Bean11.class).date); | ||
assertNull(JSON.parseObject("{\"date\":\"\"}").to(Bean11.class).date); | ||
} | ||
|
||
public static class Bean11 { | ||
@JSONField(format = "yyyy-MM-dd") | ||
public org.joda.time.Instant date; | ||
} | ||
} |