Skip to content

[BUG] parsing ['1'] , ["1.1"] #3276

@Cooperzzy

Description

@Cooperzzy

问题描述

Integer和Long类型的 ["123"] 可以解析,Double无法解析,Character会只保留[

环境信息

  • OS信息: [e.g.:MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [e.g.:Openjdk 17.0.6]
  • 版本信息:[e.g.:Fastjson2 2.0.54]
    @Test
    public void jsonSerializationTest3() {
        String json = "{\n" +
                "    \"c\":[\"1.1\"]\n" +
                "}";

        Bean bean = JSON.parseObject(json, Bean.class);
        // com.alibaba.fastjson2.JSONException: can not cast to decimal
        System.out.println(bean.getC());
    }
    
    @Test
    public void jsonSerializationTest2() {
        String json = "{\n" +
                "    \"b\":['1']\n" +
                "}";
        Bean bean = JSON.parseObject(json, Bean.class);
        System.out.println(bean.getB()); // [
    }
    @Data
    public static class Bean {
        private Character b;
        private Double c;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions