标签:pes mvc 格式化输出 tpm apn dna dia config otc
阿里的fastjson 包升级后,可能导致返回的json 数据,字段为null时不显示等问题
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.9.13</version> </dependency>
@Configuration public class FastjsonConfiguration { @Bean public HttpMessageConverters fastjsonConverter() { FastJsonConfig fastJsonConfig = new FastJsonConfig(); //自定义格式化输出 fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero); FastJsonHttpMessageConverter4 fastjson = new FastJsonHttpMessageConverter4(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); } }
SerializerFeature 类的一些枚举值
WriteMapNullValue, WriteNullListAsEmpty // 将list的null转成 [] WriteNullStringAsEmpty // 将string的null转成 "" WriteNullNumberAsZero WriteNullBooleanAsFalse, PrettyFormat, WriteClassName, WriteDateUseDateFormat, NotWriteRootClassName, BeanToArray, WriteNonStringKeyAsString, NotWriteDefaultValue, BrowserSecure, IgnoreNonFieldGetter, WriteNonStringValueAsString,
springMVC 中设置
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json</value>
</list>
</property>
<property name="features">
<list>
<value>WriteMapNullValue</value>
<value>QuoteFieldNames</value>
</list>
</property>
<!-- <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/> -->
</bean>
标签:pes mvc 格式化输出 tpm apn dna dia config otc
原文地址:https://www.cnblogs.com/yrjns/p/11766440.html