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] JSON.toJSONString以后通过parseObject转回原对象类型报错 #1351

Closed
MartinDai opened this issue Apr 12, 2023 · 2 comments
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@MartinDai
Copy link

问题描述

JSON.toJSONString以后通过parseObject转回原对象类型报错

环境信息

请填写以下信息:

  • OS信息: MacOS 13.3.1
  • JDK信息: Openjdk 1.8.0_312
  • 版本信息:Fastjson2 2.0.26-2.0.27

重现步骤

public class Test {

    static class Inner {
        private int f1;

        public int getF1() {
            return f1;
        }

        public void setF1(int f1) {
            this.f1 = f1;
        }
    }

    List<Map<String, List<Inner>>> list = new ArrayList<>();

    public List<Map<String, List<Inner>>> getList() {
        return list;
    }

    public void setList(List<Map<String, List<Inner>>> list) {
        this.list = list;
    }

    public static void main(String[] args) {
        Test test = new Test();
        Inner inner = new Inner();
        ArrayList<Inner> innerList = new ArrayList<>();
        innerList.add(inner);
        HashMap<String, List<Inner>> map = new HashMap<>();
        map.put("innerList", innerList);
        List<Map<String, List<Inner>>> list = new ArrayList<>();
        list.add(map);
        test.setList(list);
        String toJson = JSON.toJSONString(test);
        Test fromJson = JSON.parseObject(toJson, Test.class);
        System.out.println(fromJson.getList().size());
    }
}

期待的正确结果

可以正常转回原来的类型对象

相关日志输出

Exception in thread "main" com.alibaba.fastjson2.JSONException: illegal fieldName input0, offset 30, character 0, line 1, column 31, fastjson-version 2.0.27 {"list":[{"innerList":[{"f1":0}]}]}
at com.alibaba.fastjson2.JSONReaderUTF16.readFieldNameHashCode(JSONReaderUTF16.java:1055)
at com.alibaba.fastjson2.reader.ORG_2_1_Inner.readObject(Unknown Source)
at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:500)
at com.alibaba.fastjson2.reader.ObjectReaderImplMapTyped.readObject(ObjectReaderImplMapTyped.java:344)
at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:541)
at com.alibaba.fastjson2.reader.ObjectReaderImplMapTyped.readObject(ObjectReaderImplMapTyped.java:344)
at com.alibaba.fastjson2.reader.ORG_1_1_Test.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:644)
at com.doodl6.springboot.rocketmq.consumer.Test.main(Test.java:46)

附加信息

在Fastjson2 2.0.25版本是可以正常转回去的

@MartinDai MartinDai added the bug Something isn't working label Apr 12, 2023
@wenshao wenshao added this to the 2.0.28 milestone Apr 12, 2023
@wenshao wenshao added the fixed label Apr 12, 2023
@wenshao
Copy link
Member

wenshao commented Apr 12, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.28-SNAPSHOT/
问题已修复,请帮忙有2.0.8-SNAPSHOT版本验证,2.0.28版本预计会在周末发布

@wenshao
Copy link
Member

wenshao commented Apr 15, 2023

@wenshao wenshao closed this as completed Apr 15, 2023
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