diff --git a/milky-common/src/main/java/cn/sliew/milky/common/util/JacksonUtil.java b/milky-common/src/main/java/cn/sliew/milky/common/util/JacksonUtil.java index 6341ec6..d960c2a 100644 --- a/milky-common/src/main/java/cn/sliew/milky/common/util/JacksonUtil.java +++ b/milky-common/src/main/java/cn/sliew/milky/common/util/JacksonUtil.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -16,7 +17,10 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; /** * jackson utility class. @@ -28,9 +32,10 @@ public class JacksonUtil { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); static { - OBJECT_MAPPER.registerModule(new JavaTimeModule()); - OBJECT_MAPPER.registerModule(new Jdk8Module()); - OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + OBJECT_MAPPER.registerModule(new JavaTimeModule()) + .registerModule(new Jdk8Module()) + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); } private JacksonUtil() { @@ -136,7 +141,8 @@ public static T toObject(JsonNode jsonNode, TypeReference typeReference) } public static Map toMap(JsonNode jsonNode) { - return toObject(jsonNode, new TypeReference>() {}); + return toObject(jsonNode, new TypeReference>() { + }); } public static boolean checkJsonValid(String json) {