cn.coufran.springboot.starter.api.config.SpringWebMvcConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coufran-spring-boot-starter-api Show documentation
Show all versions of coufran-spring-boot-starter-api Show documentation
Spring Boot starter,使用fastjson替换默认的jackson。
package cn.coufran.springboot.starter.api.config;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Spring Web MVC配置
* @author liuhuiming
* @since 1.0.0
* @version 1.0.0
*/
@Configuration
public class SpringWebMvcConfig implements WebMvcConfigurer {
/**
* POM文件中移除了默认的jackson依赖,手动配置fastjson converter。
*/
public void extendMessageConverters(List> converters) {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
converters.add(converter);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy