diff --git a/common/src/main/java/com/alibaba/otter/canal/common/utils/JsonUtils.java b/common/src/main/java/com/alibaba/otter/canal/common/utils/JsonUtils.java index bcaccb89..fe2bdcee 100644 --- a/common/src/main/java/com/alibaba/otter/canal/common/utils/JsonUtils.java +++ b/common/src/main/java/com/alibaba/otter/canal/common/utils/JsonUtils.java @@ -7,11 +7,8 @@ import java.net.InetAddress; import java.util.Arrays; import java.util.List; -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONFactory; -import com.alibaba.fastjson2.TypeReference; +import com.alibaba.fastjson2.*; import com.alibaba.fastjson2.filter.PropertyFilter; -import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.writer.ObjectWriter; @@ -32,11 +29,11 @@ public class JsonUtils { } public static T unmarshalFromByte(byte[] bytes, Class targetClass) { - return (T) JSON.parseObject(bytes, targetClass);// 默认为UTF-8 + return (T) JSON.parseObject(bytes, targetClass, JSONReader.Feature.SupportAutoType);// 默认为UTF-8 } public static T unmarshalFromByte(byte[] bytes, TypeReference type) { - return (T) JSON.parseObject(bytes, type.getType()); + return (T) JSON.parseObject(bytes, type.getType(), JSONReader.Feature.SupportAutoType); } public static byte[] marshalToByte(Object obj) { @@ -48,11 +45,11 @@ public class JsonUtils { } public static T unmarshalFromString(String json, Class targetClass) { - return (T) JSON.parseObject(json, targetClass);// 默认为UTF-8 + return (T) JSON.parseObject(json, targetClass, JSONReader.Feature.SupportAutoType);// 默认为UTF-8 } public static T unmarshalFromString(String json, TypeReference type) { - return (T) JSON.parseObject(json, type);// 默认为UTF-8 + return (T) JSON.parseObject(json, type, JSONReader.Feature.SupportAutoType);// 默认为UTF-8 } public static String marshalToString(Object obj) {