Skip to content

[BUG] 注册了Long全局的转换设置后,会多出两个引号 #3932

@moliu

Description

@moliu
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.writer.ObjectWriters;
import lombok.Data;

import java.io.Serializable;

public class SimpleTest {

    public static void main(String[] args) {
        JSON.register(Long.class, ObjectWriters.ofToString(Object::toString));
        String str = "{\"id\":958829775217152}";
        JSONObject obj = (JSONObject) JSON.parse(str.getBytes());
        SerializeTest serializeTest = obj.toJavaObject(SerializeTest.class);
        System.out.println(JSONObject.toJSONString(serializeTest));
    }

    @Data
    public static class SerializeTest implements Serializable {

        private String id;

    }
}

输出{"id":""958829775217152""}

不确定这是不是个bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions