diff --git a/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java index b7358aec7..05841a214 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java @@ -49,11 +49,11 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.type.TypeFactory; /** - * Generic Jackson 2-based {@link RedisSerializer} that maps {@link Object objects} to and from {@literal JSON} - * using dynamic typing. + * Generic Jackson 2-based {@link RedisSerializer} that maps {@link Object objects} to and from {@literal JSON} using + * dynamic typing. *

- * {@literal JSON} reading and writing can be customized by configuring a {@link JacksonObjectReader} - * and {@link JacksonObjectWriter}. + * {@literal JSON} reading and writing can be customized by configuring a {@link JacksonObjectReader} and + * {@link JacksonObjectWriter}. * * @author Christoph Strobl * @author Mark Paluch @@ -66,7 +66,6 @@ import com.fasterxml.jackson.databind.type.TypeFactory; */ public class GenericJackson2JsonRedisSerializer implements RedisSerializer { - private final JacksonObjectReader reader; private final JacksonObjectWriter writer; @@ -78,22 +77,22 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer - * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} - * will be used. + * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} will be + * used. * - * @param classPropertyTypeName {@link String name} of the JSON property holding type information; - * can be {@literal null}. + * @param classPropertyTypeName {@link String name} of the JSON property holding type information; can be + * {@literal null}. * @see ObjectMapper#activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String) * @see ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator, DefaultTyping, As) */ @@ -102,15 +101,15 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer - * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} - * will be used. + * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} will be + * used. * - * @param classPropertyTypeName {@link String name} of the JSON property holding type information; - * can be {@literal null}. + * @param classPropertyTypeName {@link String name} of the JSON property holding type information; can be + * {@literal null}. * @param reader {@link JacksonObjectReader} function to read objects using {@link ObjectMapper}. * @param writer {@link JacksonObjectWriter} function to write objects using {@link ObjectMapper}. * @see ObjectMapper#activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String) @@ -124,8 +123,7 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer mapper.getSerializationConfig() - .getDefaultTyper(null) != null); + this.defaultTypingEnabled = Lazy.of(() -> mapper.getSerializationConfig().getDefaultTyper(null) != null); this.typeResolver = new TypeResolver(Lazy.of(mapper::getTypeFactory), newTypeHintPropertyNameSupplier(mapper, typeHintPropertyName, this.defaultTypingEnabled)); @@ -180,12 +177,13 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer defaultTypingEnabled) { return typeHintPropertyName != null ? () -> typeHintPropertyName - : Lazy.of(() -> defaultTypingEnabled.get() ? null - : mapper.getDeserializationConfig().getDefaultTyper(null) - .buildTypeDeserializer(mapper.getDeserializationConfig(), - mapper.getTypeFactory().constructType(Object.class), Collections.emptyList()) - .getPropertyName()) - .or("@class"); + : Lazy + .of(() -> defaultTypingEnabled.get() ? null + : mapper.getDeserializationConfig().getDefaultTyper(null) + .buildTypeDeserializer(mapper.getDeserializationConfig(), + mapper.getTypeFactory().constructType(Object.class), Collections.emptyList()) + .getPropertyName()) + .or("@class"); } /** @@ -205,8 +203,8 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer objectMapperConfigurer) { - Assert.notNull(objectMapperConfigurer, - "Consumer used to configure and customize ObjectMapper must not be null"); + Assert.notNull(objectMapperConfigurer, "Consumer used to configure and customize ObjectMapper must not be null"); objectMapperConfigurer.accept(getObjectMapper()); @@ -339,8 +336,7 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer { - @Serial - private static final long serialVersionUID = 1999052150548658808L; + @Serial private static final long serialVersionUID = 1999052150548658808L; private final String classIdentifier;