web3sdk icon indicating copy to clipboard operation
web3sdk copied to clipboard

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

Open arc0035 opened this issue 4 years ago • 0 comments

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

arc0035 avatar Apr 24 '20 09:04 arc0035