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]byte[]转成jsonString后,fastjson可以解析出来,fastjson2解析则报错。 #3208

Open
dyhhh opened this issue Dec 15, 2024 · 4 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@dyhhh
Copy link

dyhhh commented Dec 15, 2024

问题描述

byte[]转成jsonString后,fastjson可以解析出来,fastjson2解析则报错。
请见下面的截图。

环境信息

  • 版本信息:[fastjson2是2.0.52,fastjson是1.2.79]
@dyhhh dyhhh added the bug Something isn't working label Dec 15, 2024
@dyhhh dyhhh closed this as completed Dec 15, 2024
@dyhhh dyhhh changed the title [BUG] [BUG]byte[]转成jsonString后,fastjson可以解析出来,fastjson2解析则报错。 Dec 15, 2024
@dyhhh
Copy link
Author

dyhhh commented Dec 15, 2024

问题描述

byte[]转成jsonString后,fastjson可以解析出来,fastjson2解析则报错。
请见下面的截图。

环境信息

  • 版本信息:[fastjson2是2.0.52,fastjson是1.2.79]

@dyhhh dyhhh reopened this Dec 15, 2024
@dyhhh
Copy link
Author

dyhhh commented Dec 15, 2024

代码
报错

@wenshao
Copy link
Member

wenshao commented Dec 23, 2024

可以文本的方式提供testcase么?

@dyhhh
Copy link
Author

dyhhh commented Dec 25, 2024

import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        // 构造数据
        byte[] data = new byte[3];
        data[0] = 1;
        data[1] = 2;
        data[2] = 3;
        // 老版本会将数据转成jsonString并放到redis里面
        String jsonString = com.alibaba.fastjson.JSONObject.toJSONString(data, SerializerFeature.WriteClassName, SerializerFeature.NotWriteDefaultValue);

        // 老版本使用fastjson解析数据,可以拿到数据
        System.out.println("fastjson解析获得数据:" + Arrays.toString((byte[]) com.alibaba.fastjson.JSON.parse(jsonString)));

        // 新版本使用fastjson2解析数据,会报错
        System.out.println("fastjson2解析获得数据:" + Arrays.toString((byte[]) com.alibaba.fastjson2.JSON.parse(jsonString)));
    }
}

@wenshao wenshao added this to the 2.0.54 milestone Jan 1, 2025
@wenshao wenshao added the fixed label 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