From e0c4a1f9857f4229f8d8ebdd2de0f4408e56ad1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C7=B3=EF=BF=BD=EF=BF=BD?= <1101766085@qq.com> Date: Wed, 30 Oct 2024 11:10:21 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20mica-redis=20=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?enableKotlinJson=20=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=A4=84=E7=90=86=20Kotlin=20json=20=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/dreamlu/mica/redis/config/MicaRedisProperties.java | 4 ++++ .../dreamlu/mica/redis/config/RedisTemplateConfiguration.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mica-redis/src/main/java/net/dreamlu/mica/redis/config/MicaRedisProperties.java b/mica-redis/src/main/java/net/dreamlu/mica/redis/config/MicaRedisProperties.java index c5e2e20a2..de8599673 100644 --- a/mica-redis/src/main/java/net/dreamlu/mica/redis/config/MicaRedisProperties.java +++ b/mica-redis/src/main/java/net/dreamlu/mica/redis/config/MicaRedisProperties.java @@ -43,6 +43,10 @@ public class MicaRedisProperties { * 序列化方式 */ private SerializerType serializerType = SerializerType.JSON; + /** + * 开启 Kotlin json 序列化 + */ + private boolean enableKotlinJson = false; /** * key 过期事件 */ diff --git a/mica-redis/src/main/java/net/dreamlu/mica/redis/config/RedisTemplateConfiguration.java b/mica-redis/src/main/java/net/dreamlu/mica/redis/config/RedisTemplateConfiguration.java index 9272fb3a0..029c86ab0 100644 --- a/mica-redis/src/main/java/net/dreamlu/mica/redis/config/RedisTemplateConfiguration.java +++ b/mica-redis/src/main/java/net/dreamlu/mica/redis/config/RedisTemplateConfiguration.java @@ -78,7 +78,7 @@ public RedisSerializer redisSerializer(MicaRedisProperties properties) { objectMapper.findAndRegisterModules(); // class type info to json GenericJackson2JsonRedisSerializer.registerNullValueSerializer(objectMapper, null); - if (KotlinDetector.isKotlinPresent()) { + if (KotlinDetector.isKotlinPresent() && properties.isEnableKotlinJson()) { objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.EVERYTHING, As.PROPERTY); } else { objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, As.PROPERTY);