[BUG] fastJson2.x序列化,SerializeConfig.put(Integer.class, ToStringSerializer.instance)未生效 #3157
Closed
Description
问题描述
使用 SerializeConfig.put(Integer.class, ToStringSerializer.instance)进行序列化,将integer类型转成string类型,未生效;
环境信息
- OS信息: [e.g.:macOS 14.5 M1 PRO 16 GB]
- JDK信息: [e.g.:Openjdk 11.0.23]
- 版本信息:[e.g.:Fastjson2 2.0.53]
重现步骤
public class App {
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;
}
}
public static void main( String[] args )
{
SerializeConfig stringSerializeConfig = new SerializeConfig();
stringSerializeConfig.put(Integer.class, ToStringSerializer.instance);
stringSerializeConfig.put(Long.class, ToStringSerializer.instance);
People one = new People(10, "aaa", 10000000L);
System.out.println(JSON.toJSONString(one, stringSerializeConfig, new SerializerFeature[0]));
}
}
期待的正确结果
{"age":"10","hairNums":"10000000","name":"aaa"}
相关日志输出
{"age":10,"hairNums":"10000000","name":"aaa"}