Json解析,忽略未知字段
This commit is contained in:
parent
575340ec49
commit
ab2e436a31
|
@ -1,7 +1,6 @@
|
||||||
package net.maku.framework.common.utils;
|
package net.maku.framework.common.utils;
|
||||||
|
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -36,7 +35,7 @@ public class AddressUtils {
|
||||||
return UNKNOWN;
|
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());
|
return String.format("%s %s", address.getPro(), address.getCity());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("根据IP获取地址异常 {}", ip);
|
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.ArrayUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -16,6 +17,10 @@ import java.util.List;
|
||||||
public class JsonUtils {
|
public class JsonUtils {
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
public static String toJsonString(Object object) {
|
public static String toJsonString(Object object) {
|
||||||
try {
|
try {
|
||||||
return objectMapper.writeValueAsString(object);
|
return objectMapper.writeValueAsString(object);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user