From 0147f8f45312084b4c467a3d2d9590c736d6cff4 Mon Sep 17 00:00:00 2001 From: "le.kuang" <1741461577@qq.com> Date: Thu, 23 Feb 2023 10:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8fastJson=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=99=A8=E8=A7=A3=E5=86=B3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=BF=94=E5=9B=9EString=20=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/CommonConfiguration.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 austin-web/src/main/java/com/java3y/austin/web/config/CommonConfiguration.java diff --git a/austin-web/src/main/java/com/java3y/austin/web/config/CommonConfiguration.java b/austin-web/src/main/java/com/java3y/austin/web/config/CommonConfiguration.java new file mode 100644 index 0000000..925ea16 --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/web/config/CommonConfiguration.java @@ -0,0 +1,34 @@ +package com.java3y.austin.web.config; + +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import com.google.common.collect.Lists; +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; + +import java.util.List; + +/** + * @author kl + * @version 1.0.0 + * @description 通用配置 + * @date 2023/2/23 10:40 + */ +@Configuration +public class CommonConfiguration { + + /** + * FastJson 消息转换器 格式化输出json + * + * @return + */ + @Bean + public HttpMessageConverters fastJsonHttpMessageConverters() { + FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); + List supportedMediaTypes = Lists.newArrayList(); + supportedMediaTypes.add(MediaType.APPLICATION_JSON); + fastConverter.setSupportedMediaTypes(supportedMediaTypes); + return new HttpMessageConverters(fastConverter); + } +}