升级Fastjson到Fastjson2

This commit is contained in:
WuPeng
2022-11-05 20:49:56 +08:00
parent fb1d9ca50a
commit ab909feedf
68 changed files with 120 additions and 114 deletions

View File

@@ -2,11 +2,13 @@ package com.genersoft.iot.vmp.utils.redis;
import java.nio.charset.Charset;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter.Feature;
/**
* @description:使用fastjson实现redis的序列化
@@ -29,7 +31,7 @@ public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
if (t == null) {
return new byte[0];
}
return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
}
@Override
@@ -38,6 +40,6 @@ public class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
return null;
}
String str = new String(bytes, DEFAULT_CHARSET);
return (T) JSON.parseObject(str, clazz);
return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
}
}

View File

@@ -3,7 +3,7 @@ package com.genersoft.iot.vmp.utils.redis;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
import gov.nist.javax.sip.stack.UDPMessageChannel;
import org.springframework.data.redis.core.*;