Search in sources :

Example 6 with FastJsonHttpMessageConverter4

use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4 in project new-cloud by xie-summer.

the class WebMvcConfigurer method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig config = new FastJsonConfig();
    config.setSerializerFeatures(// 保留空的字段
    SerializerFeature.WriteMapNullValue, // String null -> ""
    SerializerFeature.WriteNullStringAsEmpty, // Number null -> 0
    SerializerFeature.WriteNullNumberAsZero);
    converter.setFastJsonConfig(config);
    converter.setDefaultCharset(Charset.forName("UTF-8"));
    converters.add(converter);
}
Also used : FastJsonHttpMessageConverter4(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4) FastJsonConfig(com.alibaba.fastjson.support.config.FastJsonConfig)

Example 7 with FastJsonHttpMessageConverter4

use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4 in project new-cloud by xie-summer.

the class WebMvcConfigurer method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig config = new FastJsonConfig();
    config.setSerializerFeatures(// 保留空的字段
    SerializerFeature.WriteMapNullValue, // String null -> ""
    SerializerFeature.WriteNullStringAsEmpty, // Number null -> 0
    SerializerFeature.WriteNullNumberAsZero);
    converter.setFastJsonConfig(config);
    converter.setDefaultCharset(Charset.forName("UTF-8"));
    converters.add(converter);
}
Also used : FastJsonHttpMessageConverter4(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4) FastJsonConfig(com.alibaba.fastjson.support.config.FastJsonConfig)

Example 8 with FastJsonHttpMessageConverter4

use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4 in project vip by guangdada.

the class FastjsonConfig method fastJsonHttpMessageConverter.

@Bean
public FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter() {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.BrowserCompatible);
    fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
    ValueFilter valueFilter = new ValueFilter() {

        public Object process(Object o, String s, Object o1) {
            if (null == o1) {
                o1 = "";
            }
            return o1;
        }
    };
    fastJsonConfig.setSerializeFilters(valueFilter);
    converter.setFastJsonConfig(fastJsonConfig);
    return converter;
}
Also used : FastJsonHttpMessageConverter4(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4) FastJsonConfig(com.alibaba.fastjson.support.config.FastJsonConfig) ValueFilter(com.alibaba.fastjson.serializer.ValueFilter) Bean(org.springframework.context.annotation.Bean)

Example 9 with FastJsonHttpMessageConverter4

use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4 in project vip by guangdada.

the class FastjsonConfig method fastJsonHttpMessageConverter.

@Bean
public FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter() {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.BrowserCompatible);
    fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
    ValueFilter valueFilter = new ValueFilter() {

        public Object process(Object o, String s, Object o1) {
            if (null == o1) {
                o1 = "";
            }
            return o1;
        }
    };
    fastJsonConfig.setSerializeFilters(valueFilter);
    converter.setFastJsonConfig(fastJsonConfig);
    return converter;
}
Also used : FastJsonHttpMessageConverter4(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4) FastJsonConfig(com.alibaba.fastjson.support.config.FastJsonConfig) ValueFilter(com.alibaba.fastjson.serializer.ValueFilter) Bean(org.springframework.context.annotation.Bean)

Example 10 with FastJsonHttpMessageConverter4

use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4 in project spring-cloud by Rogge666.

the class WebMvcConfigurer method configureMessageConverters.

// 使用阿里 FastJson 作为JSON MessageConverter
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig config = new FastJsonConfig();
    // 保留空的字段
    config.setSerializerFeatures(// 保留空的字段
    SerializerFeature.WriteMapNullValue, // String null -> ""
    SerializerFeature.WriteNullStringAsEmpty, // 使枚举返回ordinal
    SerializerFeature.WriteEnumUsingToString, // Number null -> 0
    SerializerFeature.WriteNullNumberAsZero);
    converter.setFastJsonConfig(config);
    converter.setDefaultCharset(Charset.forName("UTF-8"));
    converters.add(converter);
}
Also used : FastJsonHttpMessageConverter4(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4) FastJsonConfig(com.alibaba.fastjson.support.config.FastJsonConfig)

Aggregations

FastJsonConfig (com.alibaba.fastjson.support.config.FastJsonConfig)12 FastJsonHttpMessageConverter4 (com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4)12 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)2 Bean (org.springframework.context.annotation.Bean)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Method (java.lang.reflect.Method)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpInputMessage (org.springframework.http.HttpInputMessage)1 HttpOutputMessage (org.springframework.http.HttpOutputMessage)1