-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved LocalDateTime format support, for issue #2093
- Loading branch information
Showing
7 changed files
with
90 additions
and
7 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
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
38 changes: 38 additions & 0 deletions
38
core/src/test/java/com/alibaba/fastjson2/issues_2000/Issue2093.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,38 @@ | ||
package com.alibaba.fastjson2.issues_2000; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2093 { | ||
@Test | ||
public void test() { | ||
LocalDateTime ldt = LocalDateTime.of(2017, 7, 6, 12, 13, 14); | ||
Bean bean = new Bean(); | ||
bean.times = new ArrayList<>(); | ||
bean.times.add(ldt); | ||
bean.timeMap = new HashMap<>(); | ||
bean.timeMap.put("time", ldt); | ||
|
||
String str = JSON.toJSONString(bean); | ||
assertEquals("{\"timeMap\":{\"time\":\"12:13:14\"},\"times\":[\"12:13:14\"]}", str); | ||
} | ||
|
||
@Data | ||
public static class Bean { | ||
@JSONField(format = "HH:mm:ss") | ||
private List<LocalDateTime> times; | ||
|
||
@JSONField(format = "HH:mm:ss") | ||
private Map<String, LocalDateTime> timeMap; | ||
} | ||
} |
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