fastjson轉換器配置
阿新 • • 發佈:2019-02-04
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework .context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Created by langhsu on 2017/10/23.
*/
@Configuration
@ConditionalOnClass({JSON.class})
public class FastJsonHttpMessageConvertersConfiguration {
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.DisableCircularReferenceDetect
);
fastConverter.setFastJsonConfig(fastJsonConfig);
return fastConverter;
}
// @Bean
// public HttpMessageConverters httpMessageConverters(){
// FastJsonHttpMessageConverter jsonHttpMessageConverter = fastJsonHttpMessageConverter();
// return new HttpMessageConverters(jsonHttpMessageConverter);
// }
}