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 a752ab4e3..ecf6c9c95 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java @@ -43,8 +43,22 @@ public class Jackson2JsonRedisSerializer implements RedisSerializer { private ObjectMapper objectMapper = new ObjectMapper(); + /** + * Creates a new {@link Jackson2JsonRedisSerializer} for the given target {@link Class}. + * + * @param type + */ public Jackson2JsonRedisSerializer(Class type) { - this.javaType = TypeFactory.defaultInstance().constructType(type); + this.javaType = getJavaType(type); + } + + /** + * Creates a new {@link Jackson2JsonRedisSerializer} for the given target {@link JavaType}. + * + * @param type + */ + public Jackson2JsonRedisSerializer(JavaType javaType) { + this.javaType = javaType; } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java index 544b7467d..c34f78f4d 100644 --- a/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java @@ -15,13 +15,13 @@ */ package org.springframework.data.redis.serializer; +import java.nio.charset.Charset; + import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.type.TypeFactory; import org.codehaus.jackson.type.JavaType; import org.springframework.util.Assert; -import java.nio.charset.Charset; - /** * {@link RedisSerializer} that can read and write JSON using Jackson's * {@link ObjectMapper}. @@ -40,8 +40,22 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { private ObjectMapper objectMapper = new ObjectMapper(); + /** + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link Class}. + * + * @param type + */ public JacksonJsonRedisSerializer(Class type) { - this.javaType = TypeFactory.defaultInstance().constructType(type); + this.javaType = getJavaType(type); + } + + /** + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link JavaType}. + * + * @param javaType + */ + public JacksonJsonRedisSerializer(JavaType javaType) { + this.javaType = javaType; } @SuppressWarnings("unchecked")