2020import org .springframework .core .serializer .DefaultSerializer ;
2121import org .springframework .core .serializer .support .DeserializingConverter ;
2222import org .springframework .core .serializer .support .SerializingConverter ;
23+ import org .springframework .data .redis .util .RedisAssertions ;
2324import org .springframework .lang .Nullable ;
24- import org .springframework .util .Assert ;
2525
2626/**
27- * Java Serialization Redis serializer. Delegates to the default (Java based) {@link DefaultSerializer serializer} and
28- * {@link DefaultDeserializer}. This {@link RedisSerializer serializer} can be constructed with either custom
29- * {@link ClassLoader} or own {@link Converter converters}.
27+ * Java Serialization {@link RedisSerializer}.
28+ * <p>
29+ * Delegates to the default (Java-based) {@link DefaultSerializer serializer}
30+ * and {@link DefaultDeserializer deserializer}.
31+ * <p>
32+ * This {@link RedisSerializer serializer} can be constructed with either a custom {@link ClassLoader}
33+ * or custom {@link Converter converters}.
3034 *
3135 * @author Mark Pollack
3236 * @author Costin Leau
3337 * @author Mark Paluch
3438 * @author Christoph Strobl
39+ * @author John Blum
3540 */
3641public class JdkSerializationRedisSerializer implements RedisSerializer <Object > {
3742
3843 private final Converter <Object , byte []> serializer ;
3944 private final Converter <byte [], Object > deserializer ;
4045
4146 /**
42- * Creates a new {@link JdkSerializationRedisSerializer} using the default class loader .
47+ * Creates a new {@link JdkSerializationRedisSerializer} using the default {@link ClassLoader} .
4348 */
4449 public JdkSerializationRedisSerializer () {
4550 this (new SerializingConverter (), new DeserializingConverter ());
4651 }
4752
4853 /**
49- * Creates a new {@link JdkSerializationRedisSerializer} using a {@link ClassLoader}.
54+ * Creates a new {@link JdkSerializationRedisSerializer} with the given {@link ClassLoader} used to
55+ * resolve {@link Class types} during deserialization.
5056 *
51- * @param classLoader the {@link ClassLoader} to use for deserialization. Can be {@literal null}.
57+ * @param classLoader {@link ClassLoader} used to resolve {@link Class types} for deserialization;
58+ * can be {@literal null}.
5259 * @since 1.7
5360 */
5461 public JdkSerializationRedisSerializer (@ Nullable ClassLoader classLoader ) {
5562 this (new SerializingConverter (), new DeserializingConverter (classLoader ));
5663 }
5764
5865 /**
59- * Creates a new {@link JdkSerializationRedisSerializer} using a {@link Converter converters} to serialize and
60- * deserialize objects.
66+ * Creates a new {@link JdkSerializationRedisSerializer} using {@link Converter converters} to serialize and
67+ * deserialize {@link Object objects} .
6168 *
62- * @param serializer must not be {@literal null}
63- * @param deserializer must not be {@literal null}
69+ * @param serializer {@link Converter} used to serialize an {@link Object} to a byte array;
70+ * must not be {@literal null}.
71+ * @param deserializer {@link Converter} used to deserialize and convert a byte arra into an {@link Object};
72+ * must not be {@literal null}
73+ * @throws IllegalArgumentException if either the given {@code serializer} or {@code deserializer}
74+ * are {@literal null}.
6475 * @since 1.7
6576 */
66- public JdkSerializationRedisSerializer (Converter <Object , byte []> serializer , Converter <byte [], Object > deserializer ) {
77+ public JdkSerializationRedisSerializer (Converter <Object , byte []> serializer ,
78+ Converter <byte [], Object > deserializer ) {
6779
68- Assert .notNull (serializer , "Serializer must not be null" );
69- Assert .notNull (deserializer , "Deserializer must not be null" );
70-
71- this .serializer = serializer ;
72- this .deserializer = deserializer ;
80+ this .serializer = RedisAssertions .requireObject (serializer , "Serializer must not be null" );
81+ this .deserializer = RedisAssertions .requireObject (deserializer , "Deserializer must not be null" );
7382 }
7483
84+ @ Override
7585 public Object deserialize (@ Nullable byte [] bytes ) {
7686
7787 if (SerializationUtils .isEmpty (bytes )) {
@@ -80,20 +90,22 @@ public Object deserialize(@Nullable byte[] bytes) {
8090
8191 try {
8292 return deserializer .convert (bytes );
83- } catch (Exception ex ) {
84- throw new SerializationException ("Cannot deserialize" , ex );
93+ } catch (Exception cause ) {
94+ throw new SerializationException ("Cannot deserialize" , cause );
8595 }
8696 }
8797
8898 @ Override
8999 public byte [] serialize (@ Nullable Object object ) {
100+
90101 if (object == null ) {
91102 return SerializationUtils .EMPTY_ARRAY ;
92103 }
104+
93105 try {
94106 return serializer .convert (object );
95- } catch (Exception ex ) {
96- throw new SerializationException ("Cannot serialize" , ex );
107+ } catch (Exception cause ) {
108+ throw new SerializationException ("Cannot serialize" , cause );
97109 }
98110 }
99111}
0 commit comments