mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
27
hutool-json/src/test/java/cn/hutool/json/JSONWriterTest.java
Executable file
27
hutool-json/src/test/java/cn/hutool/json/JSONWriterTest.java
Executable file
@@ -0,0 +1,27 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class JSONWriterTest {
|
||||
|
||||
@Test
|
||||
public void writeDateTest() {
|
||||
final JSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setDateFormat("yyyy-MM-dd"))
|
||||
.set("date", DateUtil.parse("2022-09-30"));
|
||||
|
||||
// 日期原样写入
|
||||
final Date date = jsonObject.getDate("date");
|
||||
Assert.assertEquals("2022-09-30 00:00:00", date.toString());
|
||||
|
||||
// 自定义日期格式生效
|
||||
Assert.assertEquals("{\"date\":\"2022-09-30\"}", jsonObject.toString());
|
||||
|
||||
// 自定义日期格式解析生效
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonObject.toString(), JSONConfig.of().setDateFormat("yyyy-MM-dd"));
|
||||
Assert.assertEquals(String.class, parse.get("date").getClass());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user