From e19bf1ecff96094fb6efad5e42395669101ffcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E7=BB=8D=E9=94=A6?= Date: Wed, 25 May 2022 10:22:26 +0800 Subject: [PATCH] Fastjson2 compatible fix (#4189) * update fastjson2 version, 2.0.2 -> 2.0.3 * update fastjson & druid version * bug fix for fastjson2 compatible --- .../alibaba/otter/canal/common/utils/JsonUtils.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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) {