zoukankan      html  css  js  c++  java
  • Spring Boot-FastJson

    依赖:

    <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.60</version>
            </dependency>

    然后在启动类AppApplication里添加:

    @Bean
        public HttpMessageConverters fastJsonHttpMessageConverters() {
            FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
            fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
            HttpMessageConverter<?> converter = fastJsonHttpMessageConverter;
            return new HttpMessageConverters(converter);
        }

    还有一种方法是:

    @Configuration
    public class WebConfig implements WebMvcConfigurer {
    
        @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,
                    SerializerFeature.WriteMapNullValue,
                    SerializerFeature.WriteNullStringAsEmpty,
                    SerializerFeature.DisableCircularReferenceDetect,
                    SerializerFeature.WriteNullListAsEmpty,
                    SerializerFeature.WriteDateUseDateFormat);
            List<MediaType> fastMediaTypes = new ArrayList<>();
         //需要你在请求头中写contentType,不然会有"Content type 'appliction/json' not supported" fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
    fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); converters.add(fastJsonHttpMessageConverter); } }
  • 相关阅读:
    WPF中的控件布局
    [转]WPF, WPF/E释疑
    创建像Vista任务栏一样的半透明玻璃按钮
    WPF中的TextBlock
    .net 2.0 文档生成工具
    XNA Game Studio Express 1.0正式版 发布
    WPF免费视频教程,来自Lynda.com
    WPF中的ControlTemplate(控件模板)
    获奖啦, 微软亚洲研究院第九届学生实践项目
    [转]让用户通过宏和插件向您的 .NET 应用程序添加功能
  • 原文地址:https://www.cnblogs.com/KuroNJQ/p/11188191.html
Copyright © 2011-2022 走看看