关于SpringBoot项目的Json

关于SpringBoot项目的JSON

  • 其实SpringBoot项目里的pom.xml中的spring-boot-starter-web这个依赖里,存在一个名为spring-boot-starter-json的依赖,而spring-boot-starter-json这个依赖中,又包含spring-boot-starter-json这个依赖,也就是说,SpringBoot项目已经有默认的JSON库也就是jackson。

因此不用像其他spring项目一样在pom.xml中追加下面jar包(要加也行,不过推荐使用默认的

<dependency>
    <groupId>net.sf.json-lib</groupId>
	<artifactId>json-lib</artifactId>
	<version>2.4</version>
	<classifier>jdk15</classifier>
</dependency>
  • 使用SpringBoot项目中默认的jackson是不需要修改pom.xml,只需要在application.properties中配置下列属性
#属性设置:
#日期格式化
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#格式化输出 
spring.jackson.serialization.indent-output=true
#忽略无法转换的对象
spring.jackson.serialization.fail-on-empty-beans=false
#设置空如何序列化
spring.jackson.defaultPropertyInclusion=NON_EMPTY
#允许对象忽略json中不存在的属性
spring.jackson.deserialization.fail-on-unknown-properties=false
#允许出现特殊字符和转义符
spring.jackson.parser.allow-unquoted-control-chars=true
#允许出现单引号
spring.jackson.parser.allow-single-quotes=true

想了解更多可去-->https://download.csdn.net/download/qq_34357018/12650484

猜你喜欢

转载自blog.csdn.net/qq_34357018/article/details/107761856