Browse Source

Merge branch 'redis' of wangfan/adweb3-server into master

wangfan 4 months ago
parent
commit
e2700fcf1c

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/service/impl/GADailyReportServiceImpl.java

@@ -112,6 +112,6 @@ public class GADailyReportServiceImpl extends ServiceImpl<GADailyReportMapper, G
         // 3. 根据日期排序并返回
         return dailyStatsVOs.values().stream()
                 .sorted(Comparator.comparing(DailyStatsVO::getDate)) // 排日期升序排序
-                .collect(Collectors.toList()); // 使用toList()方法导致Redis类型解析异常
+                .collect(Collectors.toList()); // 使用toList()方法返回UnmodifiableList,导致Redis类型解析异常
     }
 }

+ 11 - 6
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/redis/CacheConfig.java

@@ -6,6 +6,8 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
 import com.fasterxml.jackson.annotation.PropertyAccessor;
 import com.fasterxml.jackson.databind.MapperFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
 
 import org.jeecg.common.modules.redis.config.RedisConfig;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -63,10 +65,14 @@ public class CacheConfig {
     @Bean(name = TTL_CACHE_MANAGER)
     public CacheManager ttlCacheManager(RedisConnectionFactory connectionFactory) {
         // 解决缓存对象转换异常问题
-        ObjectMapper objectMapper = new ObjectMapper();
-        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
-        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
-        objectMapper.configure(MapperFeature.USE_ANNOTATIONS, false); // 忽略@JsonIgnore注解,缓存所有字段
+        JsonMapper jsonMapper =
+                JsonMapper.builder()
+                        .visibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY)
+                        .activateDefaultTyping(
+                                LaissezFaireSubTypeValidator.instance,
+                                ObjectMapper.DefaultTyping.NON_FINAL)
+                        .configure(MapperFeature.USE_ANNOTATIONS, false) // 忽略@JsonIgnore注解,缓存所有字段
+                        .build();
 
         // 配置缓存默认TTL,以及键值序列化方式 - 解决乱码的问题
         RedisCacheConfiguration cacheConfiguration =
@@ -77,8 +83,7 @@ public class CacheConfig {
                                 SerializationPair.fromSerializer(new StringRedisSerializer()))
                         .serializeValuesWith(
                                 SerializationPair.fromSerializer(
-                                        new Jackson2JsonRedisSerializer(
-                                                objectMapper, Object.class)))
+                                        new Jackson2JsonRedisSerializer(jsonMapper, Object.class)))
                         .disableCachingNullValues();
 
         // 非锁写入方式