package org.linlinjava.litemall.core.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter; @Configuration
public class JacksonConfig { @Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public Jackson2ObjectMapperBuilderCustomizer customJackson() {
return new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
builder.serializerByType(LocalDateTime.class,
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.serializerByType(LocalDate.class,
new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.serializerByType(LocalTime.class,
new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.deserializerByType(LocalDateTime.class,
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.deserializerByType(LocalDate.class,
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.deserializerByType(LocalTime.class,
new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.serializationInclusion(JsonInclude.Include.NON_NULL);
builder.failOnUnknownProperties(false);
builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
};
}
}

最新文章

  1. 算法与数据结构(十三) 冒泡排序、插入排序、希尔排序、选择排序(Swift3.0版)
  2. Symantec Backup Exec 2012 Agent for Linux 卸载
  3. ios数据库常用sql语句
  4. eclipse 工程默认编码修改 JSP编码修改
  5. 【汇总】iOS开发及Xcode使用中遇到的一些报错问题汇总
  6. Tmux 常用命令与快捷键
  7. spring mvc超强的json支持,你自己根本不需要额外的配置。spring mvc都给你配置好了!!!
  8. jquery ajax跨域的完美解决方法(jsonp方式)
  9. sf空间配置
  10. MaterialViewPager
  11. Java 编程的动态性, 第4部分: 用 Javassist 进行类转换--转载
  12. (转)强大的JQuery表单验证插件 FormValidator使用介绍
  13. oracle常用视图介绍
  14. redis和spring整合使用
  15. 第四百一十二节,python接口,抽象方法抽象类
  16. Spring任务调度器之Task的使用(转)
  17. Effective C++ 随笔(2)
  18. 每日英语:Hold On: Reasons For Never Giving Up Your Dream
  19. keepalive配置db层的ha的一些注意点
  20. App启动页设计实例与技巧

热门文章

  1. 第一章:MySQL架构和历史
  2. js 数据
  3. vmbox 导入虚拟电脑之后无法上网
  4. (转)绝对路径${pageContext.request.contextPath}用法及其与web.xml中Servlet的url-pattern匹配过程
  5. 代码杂谈-python函数
  6. bzoj4311向量(线段树分治+斜率优化)
  7. Android 公告新闻消息资讯之垂直滚动效果
  8. IPO套路
  9. target到底是什么?
  10. Java 创建类的过程