4949import com .fasterxml .jackson .databind .type .TypeFactory ;
5050
5151/**
52- * Generic Jackson 2-based {@link RedisSerializer} that maps {@link Object objects} to and from {@literal JSON}
53- * using dynamic typing.
52+ * Generic Jackson 2-based {@link RedisSerializer} that maps {@link Object objects} to and from {@literal JSON} using
53+ * dynamic typing.
5454 * <p>
55- * {@literal JSON} reading and writing can be customized by configuring a {@link JacksonObjectReader}
56- * and {@link JacksonObjectWriter}.
55+ * {@literal JSON} reading and writing can be customized by configuring a {@link JacksonObjectReader} and
56+ * {@link JacksonObjectWriter}.
5757 *
5858 * @author Christoph Strobl
5959 * @author Mark Paluch
6666 */
6767public class GenericJackson2JsonRedisSerializer implements RedisSerializer <Object > {
6868
69-
7069 private final JacksonObjectReader reader ;
7170
7271 private final JacksonObjectWriter writer ;
@@ -78,22 +77,22 @@ public class GenericJackson2JsonRedisSerializer implements RedisSerializer<Objec
7877 private final TypeResolver typeResolver ;
7978
8079 /**
81- * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for
82- * default typing.
80+ * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for default
81+ * typing.
8382 */
8483 public GenericJackson2JsonRedisSerializer () {
8584 this ((String ) null );
8685 }
8786
8887 /**
89- * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for
90- * default typing using the given {@link String name}.
88+ * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for default
89+ * typing using the given {@link String name}.
9190 * <p>
92- * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS}
93- * will be used.
91+ * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} will be
92+ * used.
9493 *
95- * @param classPropertyTypeName {@link String name} of the JSON property holding type information;
96- * can be {@literal null}.
94+ * @param classPropertyTypeName {@link String name} of the JSON property holding type information; can be
95+ * {@literal null}.
9796 * @see ObjectMapper#activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String)
9897 * @see ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator, DefaultTyping, As)
9998 */
@@ -102,15 +101,15 @@ public GenericJackson2JsonRedisSerializer(@Nullable String classPropertyTypeName
102101 }
103102
104103 /**
105- * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for
106- * default typing using the given {@link String name} along with the given, required {@link JacksonObjectReader}
107- * and {@link JacksonObjectWriter} used to read/write {@link Object Objects} de/serialized as JSON.
104+ * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for default
105+ * typing using the given {@link String name} along with the given, required {@link JacksonObjectReader} and
106+ * {@link JacksonObjectWriter} used to read/write {@link Object Objects} de/serialized as JSON.
108107 * <p>
109- * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS}
110- * will be used.
108+ * In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} will be
109+ * used.
111110 *
112- * @param classPropertyTypeName {@link String name} of the JSON property holding type information;
113- * can be {@literal null}.
111+ * @param classPropertyTypeName {@link String name} of the JSON property holding type information; can be
112+ * {@literal null}.
114113 * @param reader {@link JacksonObjectReader} function to read objects using {@link ObjectMapper}.
115114 * @param writer {@link JacksonObjectWriter} function to write objects using {@link ObjectMapper}.
116115 * @see ObjectMapper#activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String)
@@ -124,8 +123,7 @@ public GenericJackson2JsonRedisSerializer(@Nullable String classPropertyTypeName
124123
125124 registerNullValueSerializer (this .mapper , classPropertyTypeName );
126125
127- StdTypeResolverBuilder typer = TypeResolverBuilder .forEverything (this .mapper )
128- .init (JsonTypeInfo .Id .CLASS , null )
126+ StdTypeResolverBuilder typer = TypeResolverBuilder .forEverything (this .mapper ).init (JsonTypeInfo .Id .CLASS , null )
129127 .inclusion (JsonTypeInfo .As .PROPERTY );
130128
131129 if (StringUtils .hasText (classPropertyTypeName )) {
@@ -169,8 +167,7 @@ private GenericJackson2JsonRedisSerializer(ObjectMapper mapper, JacksonObjectRea
169167 this .reader = RedisAssertions .requireNonNull (reader , "Reader must not be null" );
170168 this .writer = RedisAssertions .requireNonNull (writer , "Writer must not be null" );
171169
172- this .defaultTypingEnabled = Lazy .of (() -> mapper .getSerializationConfig ()
173- .getDefaultTyper (null ) != null );
170+ this .defaultTypingEnabled = Lazy .of (() -> mapper .getSerializationConfig ().getDefaultTyper (null ) != null );
174171
175172 this .typeResolver = new TypeResolver (Lazy .of (mapper ::getTypeFactory ),
176173 newTypeHintPropertyNameSupplier (mapper , typeHintPropertyName , this .defaultTypingEnabled ));
@@ -180,12 +177,13 @@ private Supplier<String> newTypeHintPropertyNameSupplier(ObjectMapper mapper, @N
180177 Lazy <Boolean > defaultTypingEnabled ) {
181178
182179 return typeHintPropertyName != null ? () -> typeHintPropertyName
183- : Lazy .of (() -> defaultTypingEnabled .get () ? null
184- : mapper .getDeserializationConfig ().getDefaultTyper (null )
185- .buildTypeDeserializer (mapper .getDeserializationConfig (),
186- mapper .getTypeFactory ().constructType (Object .class ), Collections .emptyList ())
187- .getPropertyName ())
188- .or ("@class" );
180+ : Lazy
181+ .of (() -> defaultTypingEnabled .get () ? null
182+ : mapper .getDeserializationConfig ().getDefaultTyper (null )
183+ .buildTypeDeserializer (mapper .getDeserializationConfig (),
184+ mapper .getTypeFactory ().constructType (Object .class ), Collections .emptyList ())
185+ .getPropertyName ())
186+ .or ("@class" );
189187 }
190188
191189 /**
@@ -205,8 +203,8 @@ public static void registerNullValueSerializer(ObjectMapper objectMapper, @Nulla
205203 }
206204
207205 /**
208- * Gets the configured {@link ObjectMapper} used internally by this {@link GenericJackson2JsonRedisSerializer}
209- * to de/serialize {@link Object objects} as {@literal JSON}.
206+ * Gets the configured {@link ObjectMapper} used internally by this {@link GenericJackson2JsonRedisSerializer} to
207+ * de/serialize {@link Object objects} as {@literal JSON}.
210208 *
211209 * @return the configured {@link ObjectMapper}.
212210 */
@@ -235,17 +233,17 @@ public Object deserialize(@Nullable byte[] source) throws SerializationException
235233 }
236234
237235 /**
238- * Deserialized the array of bytes containing {@literal JSON} as an {@link Object} of the given,
239- * required {@link Class type}.
236+ * Deserialized the array of bytes containing {@literal JSON} as an {@link Object} of the given, required {@link Class
237+ * type}.
240238 *
241239 * @param source array of bytes containing the {@literal JSON} to deserialize; can be {@literal null}.
242- * @param type {@link Class type} of {@link Object} from which the {@literal JSON} will be deserialized;
243- * must not be {@literal null}.
244- * @return {@literal null} for an empty source, or an {@link Object} of the given {@link Class type}
245- * deserialized from the array of bytes containing {@literal JSON}.
240+ * @param type {@link Class type} of {@link Object} from which the {@literal JSON} will be deserialized; must not be
241+ * {@literal null}.
242+ * @return {@literal null} for an empty source, or an {@link Object} of the given {@link Class type} deserialized from
243+ * the array of bytes containing {@literal JSON}.
246244 * @throws IllegalArgumentException if the given {@link Class type} is {@literal null}.
247- * @throws SerializationException if the array of bytes cannot be deserialized as an instance of
248- * the given {@link Class type}
245+ * @throws SerializationException if the array of bytes cannot be deserialized as an instance of the given
246+ * {@link Class type}
249247 */
250248 @ Nullable
251249 @ SuppressWarnings ("unchecked" )
@@ -267,20 +265,19 @@ public <T> T deserialize(@Nullable byte[] source, Class<T> type) throws Serializ
267265 }
268266
269267 /**
270- * Builder method used to configure and customize the internal Jackson {@link ObjectMapper} created by
271- * this {@link GenericJackson2JsonRedisSerializer} and used to de/serialize {@link Object objects}
272- * as {@literal JSON}.
268+ * Builder method used to configure and customize the internal Jackson {@link ObjectMapper} created by this
269+ * {@link GenericJackson2JsonRedisSerializer} and used to de/serialize {@link Object objects} as {@literal JSON}.
273270 *
274271 * @param objectMapperConfigurer {@link Consumer} used to configure and customize the internal {@link ObjectMapper};
275- * must not be {@literal null}.
272+ * must not be {@literal null}.
276273 * @return this {@link GenericJackson2JsonRedisSerializer}.
277- * @throws IllegalArgumentException if the {@link Consumer} used to configure and customize
278- * the internal {@link ObjectMapper} is {@literal null}.
274+ * @throws IllegalArgumentException if the {@link Consumer} used to configure and customize the internal
275+ * {@link ObjectMapper} is {@literal null}.
276+ * @since 3.1.5
279277 */
280278 public GenericJackson2JsonRedisSerializer configure (Consumer <ObjectMapper > objectMapperConfigurer ) {
281279
282- Assert .notNull (objectMapperConfigurer ,
283- "Consumer used to configure and customize ObjectMapper must not be null" );
280+ Assert .notNull (objectMapperConfigurer , "Consumer used to configure and customize ObjectMapper must not be null" );
284281
285282 objectMapperConfigurer .accept (getObjectMapper ());
286283
@@ -339,8 +336,7 @@ protected JavaType resolveType(byte[] source, Class<?> type) throws IOException
339336 */
340337 private static class NullValueSerializer extends StdSerializer <NullValue > {
341338
342- @ Serial
343- private static final long serialVersionUID = 1999052150548658808L ;
339+ @ Serial private static final long serialVersionUID = 1999052150548658808L ;
344340
345341 private final String classIdentifier ;
346342
0 commit comments