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

ResultEntity传入数组(DynamicBytes或BytesX)时,序列化会出现空字符串 #573

Open
arc0035 opened this issue Apr 24, 2020 · 0 comments

Comments

@arc0035
Copy link

arc0035 commented Apr 24, 2020

ResultEntity中,若传入数组,那么序列化ResultEntity会出现空字符串。

测试代码

    @Test
    public void any() throws Exception{
        DynamicBytes db = new DynamicBytes(new byte[]{1,2,3});
        ResultEntity resultEntity = new ResultEntity("aa","bytes",db );
        System.out.println(JsonUtils.toJson(resultEntity));

        Bytes3 bytes32 = new Bytes3(new byte[]{1,2,3});
        resultEntity = new ResultEntity("aa","bytes32",bytes32 );
        System.out.println(JsonUtils.toJson(resultEntity));
    }

当前结果:

{"name":"aa","type":"bytes","data":""}
{"name":"aa","type":"bytes32","data":""}

期望结果

{"name":"aa","type":"bytes","data":[Hex或Base64编码的二进制]}
{"name":"aa","type":"bytes32","data":"[Hex或Base64编码的二进制]"}

原因分析

ResultEntity在构造函数里传入DynamicBytes或定长Bytes时,会将字节数组通过UTF8转码为字符串,这一步将产生不可读的字符串。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant