DATAREDIS-354 - Made JavaType lookup configurable for Jackson RedisSerializers.
We now allow to customise the JavaType to use for a given Class<> by using the getJavaType method. Added constructor variants to JacksonJsonRedisSerializer and Jackson2JsonRedisSerializer. Original pull request: #113.
This commit is contained in:
committed by
Christoph Strobl
parent
22aa5df73e
commit
557683da51
@@ -43,8 +43,22 @@ public class Jackson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Creates a new {@link Jackson2JsonRedisSerializer} for the given target {@link Class}.
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public Jackson2JsonRedisSerializer(Class<T> 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")
|
||||
|
||||
@@ -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 <a href="http://jackson.codehaus.org/">Jackson's</a>
|
||||
* {@link ObjectMapper}.
|
||||
@@ -40,8 +40,22 @@ public class JacksonJsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link Class}.
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public JacksonJsonRedisSerializer(Class<T> 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")
|
||||
|
||||
Reference in New Issue
Block a user