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")    // 格式化日期

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM