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] 单引号的原始值boolean无法解析进对象 #3283

Open
citytianya opened this issue Jan 15, 2025 · 0 comments
Open

[BUG] 单引号的原始值boolean无法解析进对象 #3283

citytianya opened this issue Jan 15, 2025 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@citytianya
Copy link

问题描述

fastjson2 json字符串中含有单引号字符格式的布尔值时,例如'true','false',对象中定义的是primitive boolean。使用parseObject解析会报错。但fastjson1不会。

环境信息

请填写以下信息:

  • OS信息: Microsoft Windows 11
  • JDK信息 Openjdk 1.8.0_402
  • 版本信息:Fastjson2 2.0.53

重现步骤

如何操作可以重现该问题:

  1. 使用 com.alibaba.fastjson2.JSONObject#parseObject(java.lang.String, java.lang.Class<T>) 方法
  2. 输入 {'test':'true'} 数据
  3. 出现错误:
Exception in thread "main" com.alibaba.fastjson2.JSONException: syntax error : 39
	at com.alibaba.fastjson2.JSONReaderUTF8.readBoolValue(JSONReaderUTF8.java:7550)
	at com.alibaba.fastjson2.reader.ORG_1_1_Bean.readObject(Unknown Source)
	at com.alibaba.fastjson2.JSON.parseObject(JSON.java:864)
	at com.alibaba.fastjson2.JSONObject.parseObject(JSONObject.java:2107)

双引号不会出现此问题

class Bean {
        private boolean test;

        public boolean isTest() {
            return test;
        }

        public void setTest(boolean test) {
            this.test = test;
        }
    }

String text = "{'test': 'true'}";
Bean bean = JSONObject.parseObject(text, Bean.class); //报错

期待的正确结果

如fastjson1一样,能够正常解析单引号。
或者有任何方式能够自定义全局解决这个问题?因为不能确定还有多少地方会存在这样的json,最好能全局解决。

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@citytianya citytianya added the bug Something isn't working label Jan 15, 2025
@citytianya citytianya changed the title [BUG] [BUG] 单引号的原始值boolean无法解析进对象 Jan 15, 2025
@wenshao wenshao added this to the 2.0.55 milestone Jan 24, 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
Projects
None yet
Development

No branches or pull requests

2 participants