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] FastJsonConfig 配置writerFilter PropertyFilter 属性过滤,会导致KEY为空 #471

Closed
William007001 opened this issue Jun 15, 2022 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@William007001
Copy link

问题描述

简要描述您碰到的问题。
Spring mvc 模式下 FastJsonHttpMessageConverter 增加全局写过滤器,属性过滤器,过滤器中实现返回 true,导致KEY = null

环境信息

  • OS信息: [Windows 10 专业版 4Core 3.60GHz 16 GB]
  • JDK信息: [17+35-LTS-2724]
  • 版本信息:[Fastjson2 2.0.7]

重现步骤

`
@OverRide
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
List mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_JSON);
fastConverter.setSupportedMediaTypes(mediaTypes);
FastJsonConfig fastJsonConfig = new FastJsonConfig();
// fastJsonConfig.setWriterFeatures(GlobalConst.JSON_WRITER_FEATURE);
// fastJsonConfig.setReaderFeatures(GlobalConst.JSON_READER_FEATURE);
fastJsonConfig.setDateFormat(DatePattern.NORM_DATETIME_PATTERN);
fastJsonConfig.setCharset(CharsetUtil.CHARSET_UTF_8);

    fastJsonConfig.setWriterFilters(SerializerKit.getDefaultFilter(environment));
    fastConverter.setFastJsonConfig(fastJsonConfig);

    converters.add(fastConverter);
}

static class CustomizePropertyFilter implements PropertyFilter {
/**
* 属性过滤
*
* @param object
* @param name
* @param value
* @return
*/
@OverRide
public boolean apply(Object object, String name, Object value) {
return true;
}
}
`

  1. 使用 xxx.xxx 方法
  2. 输入 ... 数据
  3. 出现 ... 错误
//可在此输入示例代码

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

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

附加信息

image

@William007001 William007001 added the bug Something isn't working label Jun 15, 2022
@VictorZeng
Copy link
Collaborator

@William007001 能否提供更详细的信息,比如入参和出参

@William007001
Copy link
Author

request data
`

public class Test {

private Long id;
private String name;


public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

Map<String, List> map = new HashMap<>();
Test test = new Test();
test.setId(10L);
test.setName("test");
map.put("test", CollUtil.newArrayList(test));

`

response data

{"code":200,"data":{"test":[{null:10,null:"test"}]},"message":"请求成功","success":true}

说明:外层对象是统一封装的,data属性是接收一个泛型,只有这种情况加了属性过滤器后data里面的对象属性就会变成null,直接返回原本对象正常,感觉是泛型然后属性过滤器就有问题,1.x下正常

VictorZeng added a commit to VictorZeng/fastjson2 that referenced this issue Jun 15, 2022
@VictorZeng
Copy link
Collaborator

@William007001 问题已复现并修复,近期会发布快照版本~

@wenshao wenshao added this to the 2.0.8 milestone Jun 15, 2022
@William007001
Copy link
Author

happy

@wenshao
Copy link
Member

wenshao commented Jun 25, 2022

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

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

3 participants