springboot使用fastjson解析json数据

一、配置pon.xml

<!-- fastjson的依赖 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.15</version>
</dependency>

二、配置注入

@Bean
public HttpMessageConverters fastJsonMessageConverter() {
    // 创建FastJson的消息转换器
    FastJsonHttpMessageConverter convert = new FastJsonHttpMessageConverter();
    // 创建FastJson的配置对象
    FastJsonConfig config = new FastJsonConfig();
    // 对Json数据进行格式化
    config.setSerializerFeatures(SerializerFeature.PrettyFormat);

    convert.setFastJsonConfig(config);
    HttpMessageConverter<?> con = convert;
    return new HttpMessageConverters(con);
}

三、配置application.yml

spring:
  http:
    encoding:
      force: true

四、fastjson注解

@JSONField(format="yyyy-MM-dd HH:mm:ss")    // 格式化日期
原文地址:https://www.cnblogs.com/linding/p/12591398.html