This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3474 from fanzhongwei/master
fix issue #3473
- Loading branch information
Showing
2 changed files
with
46 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
45 changes: 45 additions & 0 deletions
45
src/test/java/com/alibaba/fastjson/serializer/issue3473/SerializeWriterJavaSqlDateTest.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,45 @@ | ||
package com.alibaba.fastjson.serializer.issue3473; | ||
|
||
import java.sql.Date; | ||
import java.text.ParseException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.time.DateUtils; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
|
||
/** | ||
* package com.alibaba.fastjson.serializer.issue3473 <br/> | ||
* description: java.sql.Date序列化测试 <br/> | ||
* Copyright 2019 thunisoft, Inc. All rights reserved. | ||
* | ||
* @author fanzhongwei | ||
* @date 20-9-29 | ||
*/ | ||
public class SerializeWriterJavaSqlDateTest { | ||
|
||
private Map<String, Object> data = new HashMap<String, Object>(1, 1); | ||
|
||
@Before | ||
public void before() throws ParseException { | ||
data.put("sqlDate", new Date(DateUtils.parseDate("2020-09-29", "yyyy-MM-dd") | ||
.getTime())); | ||
} | ||
|
||
@Test | ||
public void yyyy_MM_dd_HH_mm_ss_test() { | ||
String json = JSON.toJSONString(data, SerializerFeature.WriteDateUseDateFormat); | ||
Assert.assertEquals("{\"sqlDate\":\"2020-09-29 00:00:00\"}", json); | ||
} | ||
|
||
@Test | ||
public void yyyy_MM_dd_test() { | ||
String json = JSON.toJSONString(data); | ||
Assert.assertEquals("{\"sqlDate\":\"2020-09-29\"}", json); | ||
} | ||
} |