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] 内部类公开构造器使用 FieldBased 模式反序列化失败 #751

Closed
AlbumenJ opened this issue Sep 11, 2022 · 2 comments
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@AlbumenJ
Copy link

问题描述

简要描述您碰到的问题。

内部类公开构造器使用 FieldBased 模式反序列化失败

重现步骤

测试用例:

public class A {
    public static void main(String[] args) {
        byte[] bytes = JSONB.toBytes(new Data());
        Object o = JSONB.parseObject(bytes, Data.class, JSONReader.Feature.FieldBased);
        System.out.println(o.getClass());
    }


    static class Data implements Serializable {
        private String mData = "";

        public Data() {
        }

        public String getData() {
            return mData;
        }

        public void setData(String data) {
            mData = data;
        }
    }
}

日志:

Exception in thread "main" java.lang.IllegalAccessError: tried to access class org.apache.dubbo.common.serialize.fastjson2.Fastjson2SecurityManager$Data from class com.alibaba.fastjson2.reader.ObjectReader_1
	at com.alibaba.fastjson2.reader.ObjectReader_1.createInstance(Unknown Source)
	at com.alibaba.fastjson2.reader.ObjectReader_1.readJSONBObject(Unknown Source)
	at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:542)
	at org.apache.dubbo.common.serialize.fastjson2.Fastjson2SecurityManager.main(Fastjson2SecurityManager.java:121)

其他信息

  1. 不使用 FieldBased 模式,正常
  2. 删除构造器,正常
  3. 内部类改公开,正常
  4. 修改 field 的名字和 getter setter 名字一样,报错
@AlbumenJ AlbumenJ added the bug Something isn't working label Sep 11, 2022
@AlbumenJ
Copy link
Author

此 case 2.0.7 正常,2.0.13 报错

@wenshao
Copy link
Member

wenshao commented Sep 16, 2022

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

@wenshao wenshao closed this as completed Sep 16, 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 fixed
Projects
None yet
Development

No branches or pull requests

2 participants