You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ldcsaa
changed the title
fastjson 能否提供字段级别的null输出控制,类似 @JsonInclude(value=Include.NON_NULL)
fastjson 能否提供字段级别的null输出控制,类似Jackson2 的 @JsonInclude(value=Include.NON_NULL) 注解
Oct 9, 2023
需求或者改进建议
fastjson2 的
JSONWriter.Feature.WriteMapNullValue
是对象级别的,序列化对象时null字段要么全部输出,要么不输出。我现在有一个场景:校验错误字段
validationErrors
在有值的时候才输出,没有值就不输出,无论是否设置了JSONWriter.Feature.WriteMapNullValue
。Jackson2 的
@JsonInclude(value=Include.NON_NULL)
能很好实现这个需求,但fastjson2 我没看到类似的功能附加信息
源码示例
目前的解决办法
我目前是通过自定义 PropertyFilter 实现,每个属性判断都要经过这个Filter,还涉及到反射操作,不知对运行效率有多大影响
The text was updated successfully, but these errors were encountered: