alibaba / alibaba/fastjson2

SpringMvc中全局设置了`JSONWriter.Feature.WriteMapNullValue`,如何单独指定某个类型设置不过滤NULL(也就是fastjson)默认序列化方式

Open
#2,212 15 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

### SpringMvc中全局设置了`JSONWriter.Feature.WriteMapNullValue`,不过滤`NULL`值,
如何针对某个类型过滤NULL值,`JSONWriter.Feature`中是否存在过滤NULL的值
```java
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter(){
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
//自定义配置
FastJsonConfig config = new FastJsonConfig();
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
config.setReaderFeatures(JSONReader.Feature.FieldBased, JSONReader.Feature.SupportArrayToBean);
config.setWriterFeatures(JSONWriter.Feature.WriteMapNullValue);
converter.setFastJsonConfig(config);
converter.setDefaultCharset(StandardCharsets.UTF_8);
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
return converter;
}
`

Contributor guide

Open the contributing guide

Research direction

Start with the FastJsonHttpMessageConverter and FastJsonConfig setup shown in the issue, then inspect the JSONWriter.Feature options related to null handling. Determine how a single type can override the global WriteMapNullValue setting, and confirm that the resulting serialization matches the default null-filtering behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.