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]Typeutils转换char类型到String类型再通过Typeutils转换回char类型时会导致char的值变成" #564

Closed
FanJiaRui opened this issue Jul 14, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@FanJiaRui
Copy link

问题描述

使用Fastjson提供的Typeutils转换char类型到String类型再通过Typeutils转换回char类型时会导致char的值变成"

原因应该是因为char类型经过Typeuitls转换为String时变成了"1",然而转换回char时取的第一个字符正好为"导致
char转字符串加双引号是否有问题不好说,但我觉得Typeuitls双向转换之后值失真应该是个bug

环境信息

请填写以下信息:

  • OS信息: Windows 10
  • JDK信息: Oracle jdk 1.8.0_201
  • 版本信息:Fastjson2 2.0.10-SNAPSHOT

重现步骤

执行以下代码

public class TestUtils {
    public static void main(String[] args) {
        char a = '1';
        String str = TypeUtils.cast(a, String.class);
        char b = TypeUtils.cast(str, char.class);
        System.out.println(a);
        System.out.println(b);
    }
}

期待的正确结果

预期输出结果为
1
1

相关日志输出

然而实际输出结果为
1
"

附加信息

@FanJiaRui FanJiaRui added the bug Something isn't working label Jul 14, 2022
@FanJiaRui FanJiaRui changed the title [BUG] [BUG]Typeutils转换char类型到String类型再通过Typeutils转换回char类型时会导致char的值变成" Jul 14, 2022
@wenshao
Copy link
Member

wenshao commented Jul 15, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.10-SNAPSHOT/
问题已经修复,请用2.0.10-SNAPSHOT版本验证,2.0.10预计在7月24日前发布

@wenshao wenshao modified the milestone: 2.0.10 Jul 15, 2022
@wenshao
Copy link
Member

wenshao commented Jul 23, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.10
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants