alibaba / alibaba/fastjson2

[BUG]fastjson2.0.53传入多个SimplePropertyPreFilter的实现类时,只生效最后一个

Open
#2,979 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
*简要描述您碰到的问题。*

### 环境信息
*请填写以下信息:*

- OS信息: [mac pro 32 GB]
- JDK信息: [java version "21.0.4" 2024-07-16 LTS]
- 版本信息:[Fastjson2 2.0.53]

### 重现步骤
```
public static void main(String[] args) {
Filter[] filters = new Filter[2];
SimplePropertyPreFilter filter1 = new SimplePropertyPreFilter(BeanB.class);
String[] exc1 = {"uname"};
filter1.getExcludes().addAll(Arrays.asList(exc1));
filters[0] = filter1;
SimplePropertyPreFilter filter2 = new SimplePropertyPreFilter(BeanB.class);
String[] exc2 = {"age"};
filter2.getExcludes().addAll(Arrays.asList(exc2));
filters[1] = filter2;

List list = new ArrayList<>();
BeanB beanB = new BeanB();
beanB.setUname("user1");
beanB.setId("1");
beanB.setAge("20");
list.add(beanB);

String str = JSON.toJSONString(list, filters, JSONWriter.Feature.WriteMapNullValue);
System.out.println(str);
}

@Data
static class BeanB {
private String uname;
private String id;
private String age;
}
```

### 期待的正确结果
[{"id":"1"}]

### 实际输出
[{"id":"1","uname":"user1"}]

Contributor guide

Open the contributing guide

Research direction

Start at the JSON.toJSONString entry point in the supplied Java reproduction and trace how multiple SimplePropertyPreFilter instances are processed. Run the example with Fastjson2 2.0.53 first; done means both uname and age are excluded and the output is [{"id":"1"}].

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.