alibaba / alibaba/fastjson2

[BUG]ValueFilter过滤对于json字符串发现没有进入apply方法,没法生效

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

Description

### 问题描述
*简要描述您碰到的问题。*
ValueFilter过滤对于json字符串发现没有进入apply方法,没法生效

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

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

### 重现步骤
*如何操作可以重现该问题:*

类似代码如下
```java
String str =
"{\"num\":\"18005509635\",\"fee\":\"2000\"}";
JSON.toJSONString(str, new Filter())

public class Filter implements ValueFilter {
@Override
public Object apply(Object object, String name, Object value) {
return ["num"].containsKey(name.toUpperCase(Locale.ENGLISH)) ? "****" : value;
}
}

```

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
"{\"num\":\"****\",\"fee\":\"2000\"}"

但是实际上还是输出原有的值"{\"num\":\"18005509635\",\"fee\":\"2000\"}" 有点奇怪

我需要将 JSON.toJSONString(JSON.parseObject(str), new Filter()) 才可以输出期待结果

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown JSON.toJSONString call and compare it with the JSON.parseObject(str) path, focusing on when ValueFilter.apply is invoked for a JSON string. Add a regression test covering the expected masked output, then verify that filtering works without requiring an explicit parse step.

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.