From 5644769f25906865aede185d69e741591c621425 Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 1 Jan 2025 13:52:24 +0800 Subject: [PATCH] add testcase for issue #3157 --- .../alibaba/fastjson/v2issues/Issue3157.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue3157.java diff --git a/fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue3157.java b/fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue3157.java new file mode 100644 index 0000000000..7b77959401 --- /dev/null +++ b/fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue3157.java @@ -0,0 +1,48 @@ +package com.alibaba.fastjson.v2issues; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializeConfig; +import com.alibaba.fastjson.serializer.ToStringSerializer; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Issue3157 { + public static class People { + private Integer age; + + private Long hairNums; + + private String name; + + public People(Integer age, String name, Long hairNums) { + this.age = age; + this.name = name; + this.hairNums = hairNums; + } + + public Integer getAge() { + return age; + } + + public String getName() { + return name; + } + + public Long getHairNums() { + return hairNums; + } + } + + @Test + public void test() { + SerializeConfig stringSerializeConfig = new SerializeConfig(); + stringSerializeConfig.put(Integer.class, ToStringSerializer.instance); + stringSerializeConfig.put(Long.class, ToStringSerializer.instance); + + People one = new People(10, "aaa", 10000000L); + assertEquals( + "{\"age\":\"10\",\"hairNums\":\"10000000\",\"name\":\"aaa\"}", + JSON.toJSONString(one, stringSerializeConfig)); + } +}