|
@@ -0,0 +1,48 @@
|
|
|
|
+package com.kmall.admin.config;
|
|
|
|
+
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
+
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.TimeZone;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author lhm
|
|
|
|
+ * @createDate 2021-12-29
|
|
|
|
+ */
|
|
|
|
+@Configuration
|
|
|
|
+public class JacksonConfig {
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public ObjectMapper objectMapper() {
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+
|
|
|
|
+ objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
|
+
|
|
|
|
+ objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
|
|
|
+
|
|
|
|
+ objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+
|
|
|
|
+ return objectMapper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(ObjectMapper objectMapper) {
|
|
|
|
+ MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
|
|
|
|
+
|
|
|
|
+ mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
|
|
|
|
+ List<MediaType> mediaTypes = new ArrayList<>();
|
|
|
|
+ mediaTypes.add(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
|
+
|
|
|
|
+ mappingJackson2HttpMessageConverter.setSupportedMediaTypes(mediaTypes);
|
|
|
|
+
|
|
|
|
+ return mappingJackson2HttpMessageConverter;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|