1. SpringBoot JSON工具包默认是Jackson,只需要引入spring-boot-starter-web依赖包,自动引入相应依赖包:

<dependency>

        <groupId>com.fasterxml.jackson.core</groupId>

        <artifactId>jackson-databind</artifactId> -->数据绑定依赖于下面两个包

        <version>2.8.7</version>

</dependency>

<dependency>

        <groupId>com.fasterxml.jackson.core</groupId>

        <artifactId>jackson-annotations</artifactId> -->注解包

        <version>2.8.0</version>

</dependency>

<dependency>

        <groupId>com.fasterxml.jackson.core</groupId>

        <artifactId>jackson-core</artifactId> -->核心包

        <version>2.8.7</version>

</dependency>

2. Jackson两种配置方式

  A. application.properties文件

# 日期格式化
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
# 日期时区
spring.jackson.time-zone=GMT+8
# 返回值null不显示
spring.jackson.default-property-inclusion=non_null

  B. bean配置

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; @Configuration
public class JacksonConfig { @Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
// 返回值过滤null或""值
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY).setSerializationInclusion(JsonInclude.Include.NON_NULL); return objectMapper;
} }

Springboot JackSon的更多相关文章

  1. Springboot Jackson配置根本方案, 日期格式化, 时区设置生效

    当项目集成配置的功能越来越多, 说不准哪个配置就影响到了什么. 比如你启用了EnableMvC, 默认配置文件配置的一些文件就失效了. 虽然约定大于配置,让springboot可以极简化构建, 但不熟 ...

  2. SpringBoot jackson传入List引起的坑

    一.jackson无法解析value为[]的json 当入参为{xxxx1:[1,2,3],xxxx2:[obj1,obj2,obj3]}时,springmvn controller接收入参写为Lon ...

  3. Springboot jackSon -序列化-详解

    在项目中有事需要对值为NULL的对象中Field不做序列化输入配置方式如下: [配置类型]: 源码包中的枚举类: public static enum Include { ALWAYS, NON_NU ...

  4. java~springboot(2022之后)~目录索引

    回到占占推荐博客索引 最近写了不过关于java,spring,微服务的相关文章,今天把它整理一下,方便大家学习与参考. java~springboot(2022之前)~目录索引 java~spring ...

  5. springboot之jackson的两种配置方式

    springboot 针对jackson是自动化配置的,如果需要修改,有两种方式: 方式一:通过application.yml 配置属性说明:## spring.jackson.date-format ...

  6. springBoot(2)---快速创建项目,初解jackson

    快速创建项目,初解jackson 一.快速创建项目 springboot官网提供了工具类自动创建web应用:网址:http://start.spring.io/ 官网页面 1.快速创建一个 选择web ...

  7. spring boot @ResponseBody转换JSON 时 Date 类型处理方法,Jackson和FastJson两种方式,springboot 2.0.9配置fastjson不生效官方解决办法

    spring boot @ResponseBody转换JSON 时 Date 类型处理方法 ,这里一共有两种不同解析方式(Jackson和FastJson两种方式,springboot我用的1.x的版 ...

  8. Jackson序列化LocalDate与Springboot集成

    前言 Java8的date API一经推出便广受好评,今日也准备用一用,然后就用出问题了.基本用法见https://www.cnblogs.com/woshimrf/p/java8-date-api. ...

  9. SpringBoot中用Fastjson替换默认的Jackson

    一:前言 经过测试,Jackson有很多不合人意的地方,因此建议用Fastjson来替换: 二:Jackson的坑 先定义实体类: @Data @AllArgsConstructor @NoArgsC ...

随机推荐

  1. Codechef August Challenge 2019 Division 2

    Preface 老年菜鸡终于开始打CC了,由于他太弱了所以只能打Div2 因为台风的原因challenge并没有写,所以水了个Rank7 A Football SB模拟题不解释 #include< ...

  2. [LeetCode] 536. Construct Binary Tree from String 从字符串创建二叉树

    You need to construct a binary tree from a string consisting of parenthesis and integers. The whole ...

  3. 第04组 团队Git现场编程实战

    组员职责分工 组员 分工 林涛(组长) 分配任务.整理数据.写博客 童圣滔 UI界面制作 林红莲 UI界面制作 潘雨佳 测评出福州最受欢迎的商圈 于瀚翔 测评出福州最受欢迎的商圈 覃鸿浩 测评出福州人 ...

  4. 编译安装php-fpm5.6 (centos 7)

    一.安装php-fpm依赖包 yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zl ...

  5. 【微信小程序】手写索引选择器(城市列表,汽车品牌选择列表)

    摘要: 小程序索引选择器,点击跳转相应条目,索引可滑动,滑动也可跳转 场景:城市选择列表, 汽车品牌选择列表 所用组件: scroll-view(小程序原生) https://developers.w ...

  6. Servlet的Listener介绍

    当Web应用在Web容器中运行时,Web应用内部会不断地发生各种事件:如Web应用被启动.Web应用被停止.用户session开始.用户session结束等.通常这些Web操作对开发者是透明的.但Se ...

  7. python2升级python3

    需求: centos环境,python2.7需要升级为python3.x 1.请先手动(再次)安装 openssl .否则你升级之后,你的pip不能下载,会各种报错的. 比如这种错误: ImportE ...

  8. 多项式 ln

    多项式 ln 定义 \(给一多项式F(x),求G(x)\equiv lnF(x)\pmod x^n\) 前置知识 \(不定积分\) \(微分\) \(多项式乘法逆\) 推式子: \[\because ...

  9. CycleBarrier与CountDownLatch原理

    CountDownLatch 众所周知,它能解决一个任务必须在其他任务完成的情况下才能执行的问题,代码层面来说就是只有计数countDown到0的时候,await处的代码才能继续向下运行,例如: im ...

  10. css设置手型光标

    因为现在主流浏览器是chrome,所以要尽量使用 cursor:pointer,不要使用 cursor:hand chrome下支持的鼠标样式 default 默认光标(通常是一个箭头) auto 默 ...