spring boot 使用fastjson

一. 使用fastjson

/**
 * fastJson序列化配置
 */
public static final FastJsonConfig FAST_JSON_CONFIG = new FastJsonConfig();
static {
    FAST_JSON_CONFIG.setSerializerFeatures(
    SerializerFeature.PrettyFormat
    ,SerializerFeature.WriteMapNullValue
    ,SerializerFeature.WriteNullListAsEmpty
    ,SerializerFeature.WriteNullStringAsEmpty);
    FAST_JSON_CONFIG.setDateFormat("yyyy-MM-dd HH:mm:ss");
}
/**
 * 使用fastJson
 * @return
 */
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
    FastJsonHttpMessageConverter4 fastConverter = new FastJsonHttpMessageConverter4();

    List fastMediaTypes = new ArrayList<>();
    fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
    fastConverter.setSupportedMediaTypes(fastMediaTypes);
    //序列化配置
    fastConverter.setFastJsonConfig(FAST_JSON_CONFIG);

    return new HttpMessageConverters(fastConverter);
}

你可能感兴趣的:(spring,boot,开源项目,spring)