From 020e5b6a54208dec6138287ef357f21979c7981c Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 15 Jan 2025 14:10:09 +0100 Subject: [PATCH] Polishing. Add missing Nullable annotations to serializers. See #3053 Original pull request: #3058 --- .../redis/serializer/GenericJackson2JsonRedisSerializer.java | 1 + .../data/redis/serializer/GenericToStringSerializer.java | 1 + .../data/redis/serializer/Jackson2JsonRedisSerializer.java | 1 + .../data/redis/serializer/JdkSerializationRedisSerializer.java | 2 ++ .../springframework/data/redis/serializer/OxmSerializer.java | 1 + .../data/redis/serializer/StringRedisSerializer.java | 2 ++ 6 files changed, 8 insertions(+) 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 3746710789..685a7abc79 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java @@ -271,6 +271,7 @@ public byte[] serialize(@Nullable Object value) throws SerializationException { } @Override + @Nullable public Object deserialize(@Nullable byte[] source) throws SerializationException { return deserialize(source, Object.class); } diff --git a/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java b/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java index a85d9d8e33..8159347b89 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java @@ -92,6 +92,7 @@ public byte[] serialize(@Nullable T value) { } @Override + @Nullable public T deserialize(@Nullable byte[] bytes) { if (bytes == null) { diff --git a/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java index daa55032a5..32d626bdd8 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java @@ -158,6 +158,7 @@ public byte[] serialize(@Nullable T value) throws SerializationException { } } + @Nullable @Override @SuppressWarnings("unchecked") public T deserialize(@Nullable byte[] bytes) throws SerializationException { diff --git a/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java index 9ed493346c..db67928a94 100644 --- a/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java @@ -84,6 +84,7 @@ public JdkSerializationRedisSerializer(Converter serializer, this.deserializer = deserializer; } + @Nullable @Override public byte[] serialize(@Nullable Object value) { @@ -98,6 +99,7 @@ public byte[] serialize(@Nullable Object value) { } } + @Nullable @Override public Object deserialize(@Nullable byte[] bytes) { diff --git a/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java b/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java index 7d98db1b64..18ceace01f 100644 --- a/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java @@ -102,6 +102,7 @@ public byte[] serialize(@Nullable Object value) throws SerializationException { return stream.toByteArray(); } + @Nullable @Override public Object deserialize(@Nullable byte[] bytes) throws SerializationException { diff --git a/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java index e8e5cd2209..b9fea3cb27 100644 --- a/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java @@ -80,11 +80,13 @@ public StringRedisSerializer(Charset charset) { this.charset = charset; } + @Nullable @Override public byte[] serialize(@Nullable String value) { return (value == null ? null : value.getBytes(charset)); } + @Nullable @Override public String deserialize(@Nullable byte[] bytes) { return (bytes == null ? null : new String(bytes, charset));