Json解析,忽略未知字段
This commit is contained in:
parent
575340ec49
commit
ab2e436a31
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user