|
@@ -22,6 +22,9 @@ package com.pig4cloud.pigx.common.core.config;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
+import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
|
@@ -41,16 +44,16 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
|
public class JacksonConfig {
|
|
|
/**
|
|
|
* 针对JDK 1.8 特殊处理
|
|
|
- * .registerModule(new ParameterNamesModule())
|
|
|
- * .registerModule(new Jdk8Module())
|
|
|
- * .registerModule(new JavaTimeModule()); // new module, NOT JSR310Module
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean
|
|
|
public ObjectMapper getObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
|
|
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
|
|
- objectMapper.findAndRegisterModules();
|
|
|
+ ObjectMapper mapper = new ObjectMapper()
|
|
|
+ .registerModule(new ParameterNamesModule())
|
|
|
+ .registerModule(new Jdk8Module())
|
|
|
+ .registerModule(new JavaTimeModule()); // new module, NOT JSR310Module
|
|
|
// 忽略json字符串中不识别的属性
|
|
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
// 忽略无法转换的对象
|