springboot 針對jackson是自動化配置

spring.jackson.date-format指定日期格式,比如yyyy-MM-dd HH:mm:ss,或者具體的格式化類的全限定名

spring.jackson.deserialization是否開啓Jackson的反序列化

spring.jackson.generator是否開啓json的generators.

spring.jackson.joda-date-time-format指定Joda date/time的格式,比如yyyy-MM-ddHH:mm:ss). 如果沒有配置的話,dateformat會作爲backup

spring.jackson.locale指定json使用的Locale.

spring.jackson.mapper是否開啓Jackson通用的特性.

spring.jackson.parser是否開啓jackson的parser特性.

spring.jackson.property-naming-strategy指定PropertyNamingStrategy(CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)或者指定PropertyNamingStrategy子類的全限定類名.

spring.jackson.serialization是否開啓jackson的序列化.

spring.jackson.serialization-inclusion指定序列化時屬性的inclusion方式,具體查看JsonInclude.Include枚舉.

spring.jackson.time-zone指定日期格式化時區,比如America/Los_Angeles或者GMT+8.

 

第一種:application.properties文件

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss 
spring.jackson.time-zone=GMT+8
spring.jackson.serialization-inclusion=non_null

  

第二種:application.yml文件

spring:
  jackson:
    #日期格式化
    date-format: yyyy-MM-dd HH:mm:ss
    serialization:
       #格式化輸出 
      indent_output: true
      #忽略無法轉換的對象
      fail_on_empty_beans: false
    #設置空如何序列化
    defaultPropertyInclusion: NON_EMPTY
    deserialization:
      #允許對象忽略json中不存在的屬性
      fail_on_unknown_properties: false
    parser:
      #允許出現特殊字符和轉義符
      allow_unquoted_control_chars: true
      #允許出現單引號
      allow_single_quotes: true

  JsonInclude:

JsonInclude.Include.ALWAYS              默認

JsonInclude.Include.NON_DEFAULT     屬性爲默認值不序列化

JsonInclude.Include.NON_EMPTY         屬性爲 空(””) 或者爲 NULL 都不序列化

JsonInclude.Include.NON_NULL           屬性爲NULL   不序列化

第三種:實體上使用 @JsonInclude(JsonInclude.Include.NON_NULL)

              jackson實體轉json時,某個屬性不參加序列化時 使用@JsonIgnore 放在該屬性上

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章