|
|
@@ -3,6 +3,7 @@ package com.coffee.framework.config;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.coffee.common.config.BooleanToIntegerSerializer;
|
|
|
+import com.coffee.framework.config.convert.EnumDeserializer;
|
|
|
import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
import com.fasterxml.jackson.core.JsonParser;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
@@ -11,9 +12,8 @@ import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
|
|
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.format.Formatter;
|
|
|
-import org.springframework.format.FormatterRegistry;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
@@ -22,7 +22,6 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -33,6 +32,7 @@ import java.util.*;
|
|
|
* @Created by jianxiapc
|
|
|
*/
|
|
|
@Configuration
|
|
|
+@EnableAutoConfiguration
|
|
|
//@Profile("dev")
|
|
|
public class WebAppMvcConfig implements WebMvcConfigurer {
|
|
|
@Autowired
|
|
|
@@ -42,7 +42,6 @@ public class WebAppMvcConfig implements WebMvcConfigurer {
|
|
|
@Override
|
|
|
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
|
-// ObjectMapper objectMapper = converter.getObjectMapper();
|
|
|
// 时间格式化
|
|
|
SerializerProvider serializerProvider = objectMapper.getSerializerProvider();
|
|
|
serializerProvider.setNullValueSerializer(new JsonSerializer<Object>() {
|
|
|
@@ -67,6 +66,10 @@ public class WebAppMvcConfig implements WebMvcConfigurer {
|
|
|
return StrUtil.isBlankIfStr(text)?null:text;
|
|
|
}
|
|
|
});
|
|
|
+ SimpleModule enumModule = new SimpleModule();
|
|
|
+ enumModule.addDeserializer(Enum.class, new EnumDeserializer());
|
|
|
+ objectMapper.registerModule(enumModule);
|
|
|
+
|
|
|
objectMapper.registerModule(stringModule);
|
|
|
objectMapper.registerModule(booleanSimpleModule);
|
|
|
// 设置格式化内容
|
|
|
@@ -99,20 +102,4 @@ public class WebAppMvcConfig implements WebMvcConfigurer {
|
|
|
interceptors.forEach(registry::addInterceptor);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void addFormatters(FormatterRegistry registry) {
|
|
|
- registry.addFormatterForFieldType(String.class, new Formatter<String>() {
|
|
|
- @Override
|
|
|
- public String parse(String text, Locale locale) throws ParseException {
|
|
|
- return StrUtil.isBlankIfStr(text)?null:text;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String print(String object, Locale locale) {
|
|
|
- return object;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
}
|