[BUG]JSON.parseObject设置NameFilter参数无效
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*JSON.parseObject设置NameFilter参数无效*
### 环境信息
*请填写以下信息:*
- OS信息: Macos 14.3 (23D56)
- JDK信息: Azul Zulu version 11.0.22 - aarch64
- 版本信息:fastjson2-2.0.53
### 重现步骤
*自定义NameFilter实现时,会触发*
在JSON.toJSONString中使用NameFilter处理字段名是可以更换json 字段名,但是反序列化时使用JSON.parseObject设置NameFilter参数无效,代码如下:
```java
public class BaseConverter {
@Data
static class Ikun {
private Long seq;
}
public static void main(String[] args) {
NameFilter nf = (object, name, value) -> {
if ("seq".equals(name)) {
return "id";
}
return name;
};
System.out.println(JSON.parseObject("{\"id\": 2}", Ikun.class, nf).seq);
}
}
```
### 期待的正确结果
*至少有一个输出为 `2`*
### 相关日志输出
*`null` `null`*
#### 附加信息
*看这个[issue](https://github.com/alibaba/fastjson2/issues/2478)后续已经解决了包装内部PropertyNamingStrategy的Filter产生的bug,但是自定义的还未解决*
Contributor guide
Research direction
Start with the supplied BaseConverter reproduction and trace JSON.parseObject(String, Class, NameFilter) through the deserialization path. Compare its handling of the custom NameFilter with the related issue #2478; done means the example maps "id" to seq and prints 2, with a regression test covering the behavior.
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
- 42/100