Authored by hugufei

fix json同一个对象的反序列化为null的为题

@@ -3,6 +3,7 @@ package com.yoho.search.cache.beans; @@ -3,6 +3,7 @@ package com.yoho.search.cache.beans;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONArray; 4 import com.alibaba.fastjson.JSONArray;
5 import com.alibaba.fastjson.JSONObject; 5 import com.alibaba.fastjson.JSONObject;
  6 +import com.alibaba.fastjson.serializer.SerializerFeature;
6 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; 7 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
7 import com.yoho.search.base.utils.MD5Util; 8 import com.yoho.search.base.utils.MD5Util;
8 import com.yoho.search.cache.model.CacheObject; 9 import com.yoho.search.cache.model.CacheObject;
@@ -125,7 +126,7 @@ public class SearchCacheService { @@ -125,7 +126,7 @@ public class SearchCacheService {
125 126
126 public <T> void addSerializableObjectToCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, T object, boolean useJsonSerializable) { 127 public <T> void addSerializableObjectToCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, T object, boolean useJsonSerializable) {
127 if (useJsonSerializable) { 128 if (useJsonSerializable) {
128 - String jsonStr = JSON.toJSONString(object); 129 + String jsonStr = JSON.toJSONString(object,SerializerFeature.WriteMapNullValue,SerializerFeature.DisableCircularReferenceDetect);
129 this.addObjectToCache(redisKeyBuilder, jsonStr, searchCache); 130 this.addObjectToCache(redisKeyBuilder, jsonStr, searchCache);
130 } else { 131 } else {
131 this.addObjectToCache(redisKeyBuilder, object, searchCache); 132 this.addObjectToCache(redisKeyBuilder, object, searchCache);
@@ -83,7 +83,7 @@ public class RedisCacheUtils { @@ -83,7 +83,7 @@ public class RedisCacheUtils {
83 * @return 83 * @return
84 */ 84 */
85 private static <T> String serializeToString(T t) { 85 private static <T> String serializeToString(T t) {
86 - return JSON.toJSONString(t, SerializerFeature.WriteMapNullValue); 86 + return JSON.toJSONString(t, SerializerFeature.WriteMapNullValue,SerializerFeature.DisableCircularReferenceDetect);
87 } 87 }
88 88
89 private static <T> T unserializeFromString(String cacheObjectValue, Class<T> clazz) { 89 private static <T> T unserializeFromString(String cacheObjectValue, Class<T> clazz) {