Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fastJson2.x序列化,SerializeConfig.put(Integer.class, ToStringSerializer.instance)未生效 #3157

Open
gonghuan93cn opened this issue Nov 11, 2024 · 0 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@gonghuan93cn
Copy link

gonghuan93cn commented Nov 11, 2024

问题描述

使用 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"}

@gonghuan93cn gonghuan93cn added the bug Something isn't working label Nov 11, 2024
@wenshao wenshao added this to the 2.0.54 milestone Nov 21, 2024
@wenshao wenshao added the fixed label Jan 1, 2025
wenshao added a commit that referenced this issue Jan 1, 2025
wenshao added a commit that referenced this issue Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants