|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.data.redis.serializer.Jackson2JsonRedisSerializer<T>
public class Jackson2JsonRedisSerializer<T>
This converter can be used to bind to typed beans, or untyped
RedisSerializer that can read and write JSON using Jackson's and Jackson Databind ObjectMapper.
HashMap instances.
Note:Null objects are serialized as empty arrays and vice versa.
| Field Summary | |
|---|---|
static Charset |
DEFAULT_CHARSET
|
| Constructor Summary | |
|---|---|
Jackson2JsonRedisSerializer(Class<T> type)
|
|
| Method Summary | |
|---|---|
T |
deserialize(byte[] bytes)
Deserialize an object from the given binary data. |
protected com.fasterxml.jackson.databind.JavaType |
getJavaType(Class<?> clazz)
Returns the Jackson JavaType for the specific class. |
byte[] |
serialize(Object t)
Serialize the given object to binary data. |
void |
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets the ObjectMapper for this view. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Charset DEFAULT_CHARSET
| Constructor Detail |
|---|
public Jackson2JsonRedisSerializer(Class<T> type)
| Method Detail |
|---|
public T deserialize(byte[] bytes)
throws SerializationException
RedisSerializer
deserialize in interface RedisSerializer<T>bytes - object binary representation
SerializationException
public byte[] serialize(Object t)
throws SerializationException
RedisSerializer
serialize in interface RedisSerializer<T>t - object to serialize
SerializationExceptionpublic void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
ObjectMapper for this view. If not set, a default ObjectMapper
is used.
Setting a custom-configured ObjectMapper is one way to take further control of the JSON serialization
process. For example, an extended SerializerFactory can be configured that provides custom serializers for
specific types. The other option for refining the serialization process is to use Jackson's provided annotations on
the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary.
protected com.fasterxml.jackson.databind.JavaType getJavaType(Class<?> clazz)
JavaType for the specific class.
Default implementation returns TypeFactory.constructType(java.lang.reflect.Type), but this can be
overridden in subclasses, to allow for custom generic collection handling. For instance:
protected JavaType getJavaType(Class<?> clazz) {
if (List.class.isAssignableFrom(clazz)) {
return TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, MyBean.class);
} else {
return super.getJavaType(clazz);
}
}
clazz - the class to return the java type for
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||