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] 默认方式使用fastjson2进行反序列化,并未用到ASM生成动态代码 #352

Closed
weissxu opened this issue May 26, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@weissxu
Copy link

weissxu commented May 26, 2022

问题描述

使用方式:
com.alibaba.fastjson2.JSON#parseObject(java.lang.String, java.lang.Class)

过程:
fastjson2在反序列化时默认使用ObjectReaderCreatorASM创建ObjectReader,在ObjectReaderCreatorASM执行创建的过程中,有个match机制,默认情况下会是false,这样的话,从父类创建ObjectReader,最终使用的是Method.invoke的方式绑定字段。

com.alibaba.fastjson2.reader.ObjectReaderCreatorASM#createObjectReader

for (FieldReader fieldReader : fieldReaderArray) {
    if (fieldReader.getMethod() != null) {
        match = false;
        break;
    }

    if (fieldReader instanceof FieldReaderReadOnly
            || fieldReader.isUnwrapped()
    ) {
        match = false;
        break;
    }
}

...

if (!match) {
    return super.createObjectReader(objectClass, objectType, fieldBased, modules);
}

虽然最终可以正常的反序列化,并绑定对象,请问这是正常逻辑吗?这个过程中的核心逻辑并未用到ASM的机制?

环境信息

请填写以下信息:

  • 版本信息:[Fastjson2 2.0.3,2.0.4]

重现步骤

期待的正确结果

使用ASM机制动态生成ObjectReader子类,进行反序列化

@weissxu weissxu added the bug Something isn't working label May 26, 2022
@weissxu weissxu changed the title [BUG] [BUG] 默认方式使用fastjson2进行反序列化,并未用到ASM生成动态代码 May 26, 2022
@wenshao
Copy link
Member

wenshao commented May 26, 2022

这个问题是中间改错了,已经修复了,预计在周末发布的2.0.5版本中修复。

@wenshao wenshao added this to the 2.0.5 milestone May 26, 2022
@wenshao
Copy link
Member

wenshao commented May 28, 2022

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

@wenshao wenshao closed this as completed May 28, 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