|
@@ -0,0 +1,64 @@
|
|
|
+/*
|
|
|
+ *
|
|
|
+ * Copyright (c) 2018-2025, lengleng All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the pig4cloud.com developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: lengleng (wangiegie@gmail.com)
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+package com.pig4cloud.pigx.common.core.config;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
+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.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * JacksonConfig
|
|
|
+ *
|
|
|
+ * @author: lengleng
|
|
|
+ * @date: 2018/7/28 12:29
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+public class JacksonConfig {
|
|
|
+ /**
|
|
|
+ * 处理序列化后的1.8的日期时间格式
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ public ObjectMapper getObjectMapper() {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
|
+ javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
|
|
+ javaTimeModule.addDeserializer(LocalDateTime.class,new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ javaTimeModule.addDeserializer(LocalDate.class,new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ javaTimeModule.addDeserializer(LocalTime.class,new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
|
|
+ objectMapper.registerModule(javaTimeModule);
|
|
|
+ return objectMapper;
|
|
|
+ }
|
|
|
+}
|