We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
配置了fastjson的FastJsonHttpMessageConverter,@JSONField的serialzeFeatures,WriteNullNumberAsZero,不起效。经过验证,在1.2.83版本配置内能正常序列化,升级到2.0.40后,无效
{ "age": 0, "attr": [ 322233333333333 ], "id": 322223333333333, "name": "hello" }
1.2.38版本输出满足
{ "attr": [ 322233333333333 ], "id": 322223333333333, "name": "hello" }
import cn.hutool.core.collection.ListUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.annotation.JSONField; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/fastjson") public class TryController { @GetMapping("/serial") public User getOne(){ User hello = new User(); hello.setAge(null); hello.setName("hello"); hello.setId(322223333333333L); hello.setAttr(ListUtil.list(false, 322233333333333L)); return hello; } public static class User { @JSONField(serializeFeatures = JSONWriter.Feature.WriteNullNumberAsZero) private Integer age; private Long id; private String name; private List<Long> attr; public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } 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; } public List<Long> getAttr() { return attr; } public void setAttr(List<Long> attr) { this.attr = attr; } } }
import com.alibaba.fastjson2.support.config.FastJsonConfig; import com.alibaba.fastjson2.support.spring.http.converter.FastJsonHttpMessageConverter; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import java.util.ArrayList; import java.util.List; @Configuration public class FastjsonConfig { @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON); fastConverter.setSupportedMediaTypes(fastMediaTypes); fastConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastConverter); } }
<dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>2.0.40</version> </dependency> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2-extension-spring5</artifactId> <version>2.0.40</version> </dependency>
The text was updated successfully, but these errors were encountered:
试下最新版本?可能 #1898 解决了这个问题
Sorry, something went wrong.
No branches or pull requests
问题描述
配置了fastjson的FastJsonHttpMessageConverter,@JSONField的serialzeFeatures,WriteNullNumberAsZero,不起效。经过验证,在1.2.83版本配置内能正常序列化,升级到2.0.40后,无效
环境信息
期待结果
实际结果
具体代码
controller
fastjson配置
pom
The text was updated successfully, but these errors were encountered: