From ab2e436a314763fe11aafe626f5d0dc01553c8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Mon, 17 Oct 2022 22:11:51 +0800 Subject: [PATCH] =?UTF-8?q?Json=E8=A7=A3=E6=9E=90=EF=BC=8C=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E6=9C=AA=E7=9F=A5=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/net/maku/framework/common/utils/AddressUtils.java | 3 +-- .../src/main/java/net/maku/framework/common/utils/JsonUtils.java | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/maku-framework/src/main/java/net/maku/framework/common/utils/AddressUtils.java b/maku-framework/src/main/java/net/maku/framework/common/utils/AddressUtils.java index ea9626d..e45d1bf 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/utils/AddressUtils.java +++ b/maku-framework/src/main/java/net/maku/framework/common/utils/AddressUtils.java @@ -1,7 +1,6 @@ package net.maku.framework.common.utils; import cn.hutool.http.HttpUtil; -import cn.hutool.json.JSONUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -36,7 +35,7 @@ public class AddressUtils { return UNKNOWN; } - Address address = JSONUtil.toBean(response, Address.class); + Address address = JsonUtils.parseObject(response, Address.class); return String.format("%s %s", address.getPro(), address.getCity()); } catch (Exception e) { log.error("根据IP获取地址异常 {}", ip); diff --git a/maku-framework/src/main/java/net/maku/framework/common/utils/JsonUtils.java b/maku-framework/src/main/java/net/maku/framework/common/utils/JsonUtils.java index 89d99af..485858f 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/utils/JsonUtils.java +++ b/maku-framework/src/main/java/net/maku/framework/common/utils/JsonUtils.java @@ -3,6 +3,7 @@ package net.maku.framework.common.utils; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; @@ -16,6 +17,10 @@ import java.util.List; public class JsonUtils { private static final ObjectMapper objectMapper = new ObjectMapper(); + static { + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + public static String toJsonString(Object object) { try { return objectMapper.writeValueAsString(object);