Skip to content

Commit

Permalink
add testcase for issue #2426
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Apr 13, 2024
1 parent 86cf4ec commit bfa24a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,8 @@ public static ObjectWriterCreator getContextWriterCreator() {
public interface JSONPathCompiler {
JSONPath compile(Class objectClass, JSONPath path);
}

public static String getDefaultWriterFormat() {
return defaultWriterFormat;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.alibaba.fastjson2.issues_2400;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.JSONWriter;
import org.junit.jupiter.api.Test;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2426 {
@Test
public void test() {
String defaultWriterFormat = JSONFactory.getDefaultWriterFormat();
try {
JSON.configWriterDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = new Date(1712988987882L);
JSONWriter.Context writeContext = JSONFactory.createWriteContext();
String json = JSON.toJSONString(date, writeContext);
assertEquals("\"2024-04-13T14:16:27\"", json);
} finally {
JSON.configWriterDateFormat(defaultWriterFormat);
}
assertEquals(defaultWriterFormat, JSONFactory.getDefaultWriterFormat());
}
}

0 comments on commit bfa24a7

Please sign in to comment.