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