要在Spring Boot中配置Fastjson,可以通過以下步驟:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
public class FastjsonConfig implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
converters.add(fastConverter);
}
}
# 使用Fastjson作為JSON解析器
spring.mvc.converters.preferred-json-mapper=fastjson
這樣就可以在Spring Boot應用中使用Fastjson作為JSON解析器。