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

[QUESTION]怎么自定义JSONReader.Feature #2317

Closed
wangbiao5901 opened this issue Mar 12, 2024 · 3 comments
Closed

[QUESTION]怎么自定义JSONReader.Feature #2317

wangbiao5901 opened this issue Mar 12, 2024 · 3 comments
Labels
fixed question Further information is requested
Milestone

Comments

@wangbiao5901
Copy link

public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setWriterFeatures(
JSONWriter.Feature.WriteLongAsString
);
fastJsonConfig.setReaderFeatures(
JSONReader.Feature.IgnoreSetNullValue,
JSONReader.Feature.TrimString,
JSONReader.Feature.IgnoreNullPropertyValue,
JSONReader.Feature.IgnoreNoneSerializable,
JSONReader.Feature.NullOnError
);
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
fastConverter.setFastJsonConfig(fastJsonConfig);
fastConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
converters.add(0, fastConverter);
}
需要一个ReaderFeature, 值为空字符串("")时,也不进行Set操作,忽略该属性,应该怎么添加。
PropertyFilter ignoreEmpty = (object, name, value) -> !"".equals(value);
fastJsonConfig.setReaderFilters(ignoreEmpty);
这种方法不生效

@wangbiao5901 wangbiao5901 added the question Further information is requested label Mar 12, 2024
@wangbiao5901
Copy link
Author

环境 JDK1.8
版本 2.0.47
输入{"a":""} 期望结果 a:null

@wenshao
Copy link
Member

wenshao commented Mar 17, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/
新增加了Feature.EmptyStringAsNull,请帮忙用2.0.48-SNAPSHOT版本帮忙验证,2.0.48版本预计在3月底前发布。

@wenshao
Copy link
Member

wenshao commented Mar 25, 2024

@wenshao wenshao closed this as completed Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants