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]同时使用ContextValueFilter和ContextNameFilter时获取不到field信息 #1713

Closed
cbib-guoguifang opened this issue Aug 4, 2023 · 4 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@cbib-guoguifang
Copy link

问题描述

在单独使用ContextValueFilter时可以正确获取到field,但是在同时使用ContextValueFilter和ContextNameFilter时就会出现获取不到field的情况

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.38]

重现步骤

public static void main(String[] args) {
    UserInfo userInfo = new UserInfo();
    userInfo.setMobile("13012345678");
    userInfo.setUserId(123L);
    List<Filter> filters = new ArrayList<>();
    filters.add((ContextValueFilter) (context, object, name, value) -> {
        System.out.println("ContextValueFilter field: " + context.getField());
        return value;
    });
    filters.add((ContextNameFilter) (context, object, name, value) -> {
        System.out.println("ContextNameFilter field: " + context.getField());
        return name;
    });
    System.out.print(JSON.toJSONString(userInfo, filters.toArray(new Filter[0])));
}

附加信息

image
image
image
image

@cbib-guoguifang cbib-guoguifang added the bug Something isn't working label Aug 4, 2023
@cbib-guoguifang cbib-guoguifang changed the title [BUG] [BUG]同时使用ContextValueFilter和ContextNameFilter时获取不到field信息 Aug 4, 2023
@MoshiCoCo
Copy link
Contributor

把UserInfo里的private字段改成public试试。

@cbib-guoguifang
Copy link
Author

把UserInfo里的private字段改成public试试。

你看我的图,在单独使用ContextValueFilter时是可以正确获取到field的信息的,但是在加上ContextNameFilter时才会出现两个filter都获取不到field的信息,而且为什么要把bean里的field改成public的,这不是说笑吗

@wenshao
Copy link
Member

wenshao commented Aug 13, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.39-SNAPSHOT/
问题已修复,请帮忙用2.0.39-SNAPSHOT版本验证,2.0.39版本预计在8月27日前发布

@wenshao wenshao added this to the 2.0.39 milestone Aug 13, 2023
@wenshao wenshao added the fixed label Aug 13, 2023
@wenshao
Copy link
Member

wenshao commented Aug 15, 2023

@wenshao wenshao closed this as completed Aug 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

3 participants