Open gonghuan93cn opened 1 week ago
使用 SerializeConfig.put(Integer.class, ToStringSerializer.instance)进行序列化,将integer类型转成string类型,未生效;
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"}
问题描述
使用 SerializeConfig.put(Integer.class, ToStringSerializer.instance)进行序列化,将integer类型转成string类型,未生效;
环境信息
重现步骤
public class App { public static class People { private Integer age;
}
期待的正确结果
{"age":"10","hairNums":"10000000","name":"aaa"}
相关日志输出
{"age":10,"hairNums":"10000000","name":"aaa"}