Fastjson2 compatible fix (#4189)

* update fastjson2 version, 2.0.2 -> 2.0.3

* update fastjson & druid version

* bug fix for fastjson2 compatible
This commit is contained in:
温绍锦
2022-05-25 10:22:26 +08:00
committed by GitHub
parent a99dc0cbe8
commit e19bf1ecff

View File

@@ -7,11 +7,8 @@ import java.net.InetAddress;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.*;
import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.TypeReference;
import com.alibaba.fastjson2.filter.PropertyFilter; import com.alibaba.fastjson2.filter.PropertyFilter;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter; import com.alibaba.fastjson2.writer.ObjectWriter;
@@ -32,11 +29,11 @@ public class JsonUtils {
} }
public static <T> T unmarshalFromByte(byte[] bytes, Class<T> targetClass) { public static <T> T unmarshalFromByte(byte[] bytes, Class<T> targetClass) {
return (T) JSON.parseObject(bytes, targetClass);// 默认为UTF-8 return (T) JSON.parseObject(bytes, targetClass, JSONReader.Feature.SupportAutoType);// 默认为UTF-8
} }
public static <T> T unmarshalFromByte(byte[] bytes, TypeReference<T> type) { public static <T> T unmarshalFromByte(byte[] bytes, TypeReference<T> type) {
return (T) JSON.parseObject(bytes, type.getType()); return (T) JSON.parseObject(bytes, type.getType(), JSONReader.Feature.SupportAutoType);
} }
public static byte[] marshalToByte(Object obj) { public static byte[] marshalToByte(Object obj) {
@@ -48,11 +45,11 @@ public class JsonUtils {
} }
public static <T> T unmarshalFromString(String json, Class<T> targetClass) { public static <T> T unmarshalFromString(String json, Class<T> targetClass) {
return (T) JSON.parseObject(json, targetClass);// 默认为UTF-8 return (T) JSON.parseObject(json, targetClass, JSONReader.Feature.SupportAutoType);// 默认为UTF-8
} }
public static <T> T unmarshalFromString(String json, TypeReference<T> type) { public static <T> T unmarshalFromString(String json, TypeReference<T> 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) { public static String marshalToString(Object obj) {