diff --git a/src/main/asciidoc/reference/redis.adoc b/src/main/asciidoc/reference/redis.adoc index 11cb7b472..82a9d2506 100644 --- a/src/main/asciidoc/reference/redis.adoc +++ b/src/main/asciidoc/reference/redis.adoc @@ -288,7 +288,13 @@ public void useCallback() { [[redis:serializer]] == Serializers -From the framework perspective, the data stored in Redis is just bytes. While Redis itself supports various types, for the most part these refer to the way the data is stored rather than what it represents. It is up to the user to decide whether the information gets translated into Strings or any other objects. The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis through the `RedisSerializer` interface (package `org.springframework.data.redis.serializer`) which as the name implies, takes care of the serialization process. Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: the `StringRedisSerializer` and the `JdkSerializationRedisSerializer`. However one can use `OxmSerializer` for Object/XML mapping through Spring 3 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html[OXM] support or either `Jackson2JsonRedisSerializer` or `GenericJackson2JsonRedisSerializer` for storing data in http://en.wikipedia.org/wiki/JSON[JSON] format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes without any restrictions.[[redis:serializer]] +From the framework perspective, the data stored in Redis is just bytes. While Redis itself supports various types, for the most part these refer to the way the data is stored rather than what it represents. It is up to the user to decide whether the information gets translated into Strings or any other objects. + +The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis through the `RedisSerializer` interface (package `org.springframework.data.redis.serializer`) which as the name implies, takes care of the serialization process. + +Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: the `StringRedisSerializer` and the `JdkSerializationRedisSerializer`. However one can use `OxmSerializer` for Object/XML mapping through Spring 3 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html[OXM] support or either `Jackson2JsonRedisSerializer` or `GenericJackson2JsonRedisSerializer` for storing data in http://en.wikipedia.org/wiki/JSON[JSON] format. + +Do note that the storage format is not limited only to values - it can be used for keys, values or hashes without any restrictions. [[redis.hashmappers.root]] == Hash mapping diff --git a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java index b8e0b3eb7..0810090c5 100644 --- a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java @@ -36,7 +36,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller; /** * Parameters for testing implementations of {@link AbstractOperations} - * + * * @author Jennifer Hickey * @author Thomas Darimont * @author Christoph Strobl @@ -115,13 +115,13 @@ abstract public class AbstractOperationsTestParams { return Arrays.asList(new Object[][] { // { stringTemplate, stringFactory, stringFactory }, // - { longTemplate, stringFactory, longFactory }, // - { doubleTemplate, stringFactory, doubleFactory }, // - { rawTemplate, rawFactory, rawFactory }, // - { personTemplate, stringFactory, personFactory }, // - { xstreamStringTemplate, stringFactory, stringFactory }, // - { xstreamPersonTemplate, stringFactory, personFactory }, // - { jackson2JsonPersonTemplate, stringFactory, personFactory }, // - { genericJackson2JsonPersonTemplate, stringFactory, personFactory } }); + { longTemplate, stringFactory, longFactory }, // + { doubleTemplate, stringFactory, doubleFactory }, // + { rawTemplate, rawFactory, rawFactory }, // + { personTemplate, stringFactory, personFactory }, // + { xstreamStringTemplate, stringFactory, stringFactory }, // + { xstreamPersonTemplate, stringFactory, personFactory }, // + { jackson2JsonPersonTemplate, stringFactory, personFactory }, // + { genericJackson2JsonPersonTemplate, stringFactory, personFactory } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java index 875d05252..d0303b758 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java +++ b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java @@ -1,12 +1,12 @@ /* * Copyright 2011-2017 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,6 +44,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller; public abstract class CollectionTestParams { public static Collection testParams() { + // XStream serializer XStreamMarshaller xstream = new XStreamMarshaller(); try { @@ -129,17 +130,22 @@ public abstract class CollectionTestParams { rawTemplateLtc.setKeySerializer(stringSerializer); rawTemplateLtc.afterPropertiesSet(); - return Arrays - .asList(new Object[][] { { stringFactory, stringTemplate }, { doubleAsStringObjectFactory, stringTemplate }, - { personFactory, personTemplate }, { stringFactory, xstreamStringTemplate }, - { personFactory, xstreamPersonTemplate }, - { personFactory, jackson2JsonPersonTemplate }, { rawFactory, rawTemplate }, + return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, // + { doubleAsStringObjectFactory, stringTemplate }, // + { personFactory, personTemplate }, // + { stringFactory, xstreamStringTemplate }, // + { personFactory, xstreamPersonTemplate }, // + { personFactory, jackson2JsonPersonTemplate }, // + { rawFactory, rawTemplate }, - // lettuce - { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc }, - { doubleAsStringObjectFactory, stringTemplateLtc }, { personFactory, personTemplateLtc }, - { stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc }, - { personFactory, jackson2JsonPersonTemplateLtc }, - { rawFactory, rawTemplateLtc } }); + // lettuce + { stringFactory, stringTemplateLtc }, // + { personFactory, personTemplateLtc }, // + { doubleAsStringObjectFactory, stringTemplateLtc }, // + { personFactory, personTemplateLtc }, // + { stringFactory, xstreamStringTemplateLtc }, // + { personFactory, xstreamPersonTemplateLtc }, // + { personFactory, jackson2JsonPersonTemplateLtc }, // + { rawFactory, rawTemplateLtc } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java index 5240b45e1..ea7598522 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java @@ -1,12 +1,12 @@ /* * Copyright 2011-2017 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -40,7 +40,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller; /** * Integration test for RedisMap. - * + * * @author Costin Leau * @author Jennifer Hickey * @author Thomas Darimont @@ -150,16 +150,22 @@ public class RedisMapTests extends AbstractRedisMapTests { rawTemplateLtc.afterPropertiesSet(); return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate }, - { personFactory, personFactory, genericTemplate }, { stringFactory, personFactory, genericTemplate }, - { personFactory, stringFactory, genericTemplate }, { personFactory, stringFactory, xstreamGenericTemplate }, - { personFactory, stringFactory, jackson2JsonPersonTemplate }, { rawFactory, rawFactory, rawTemplate }, - { stringFactory, stringFactory, genericTemplateLettuce }, - { personFactory, personFactory, genericTemplateLettuce }, - { stringFactory, personFactory, genericTemplateLettuce }, - { personFactory, stringFactory, genericTemplateLettuce }, - { personFactory, stringFactory, xGenericTemplateLettuce }, - { personFactory, stringFactory, jackson2JsonPersonTemplateLettuce }, - { stringFactory, doubleFactory, stringTemplateLtc }, { stringFactory, longFactory, stringTemplateLtc }, + { personFactory, personFactory, genericTemplate }, // + { stringFactory, personFactory, genericTemplate }, // + { personFactory, stringFactory, genericTemplate }, // + { personFactory, stringFactory, xstreamGenericTemplate }, // + { personFactory, stringFactory, jackson2JsonPersonTemplate }, // + { rawFactory, rawFactory, rawTemplate }, // + + // lettuce + { stringFactory, stringFactory, genericTemplateLettuce }, // + { personFactory, personFactory, genericTemplateLettuce }, // + { stringFactory, personFactory, genericTemplateLettuce }, // + { personFactory, stringFactory, genericTemplateLettuce }, // + { personFactory, stringFactory, xGenericTemplateLettuce }, // + { personFactory, stringFactory, jackson2JsonPersonTemplateLettuce }, // + { stringFactory, doubleFactory, stringTemplateLtc }, // + { stringFactory, longFactory, stringTemplateLtc }, // { rawFactory, rawFactory, rawTemplateLtc } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java index 1171c6ba0..10cf0613a 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java @@ -1,12 +1,12 @@ /* * Copyright 2011-2017 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -60,7 +60,7 @@ public class RedisPropertiesTests extends RedisMapTests { /** * Constructs a new RedisPropertiesTests instance. - * + * * @param keyFactory * @param valueFactory * @param template @@ -289,15 +289,21 @@ public class RedisPropertiesTests extends RedisMapTests { jackson2JsonPersonTemplateLtc.setHashValueSerializer(jackson2JsonStringSerializer); jackson2JsonPersonTemplateLtc.afterPropertiesSet(); - return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate }, - { stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, genericTemplate }, - { stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, xstreamGenericTemplate }, - { stringFactory, stringFactory, jackson2JsonPersonTemplate }, + return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate }, // + { stringFactory, stringFactory, genericTemplate }, // + { stringFactory, stringFactory, genericTemplate }, // + { stringFactory, stringFactory, genericTemplate }, // + { stringFactory, stringFactory, xstreamGenericTemplate }, // + { stringFactory, stringFactory, jackson2JsonPersonTemplate }, // - { stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc }, - { stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc }, - { stringFactory, doubleFactory, genericTemplateLtc }, { stringFactory, longFactory, genericTemplateLtc }, - { stringFactory, stringFactory, xGenericTemplateLtc }, + // lettuce + { stringFactory, stringFactory, genericTemplateLtc }, // + { stringFactory, stringFactory, genericTemplateLtc }, // + { stringFactory, stringFactory, genericTemplateLtc }, // + { stringFactory, stringFactory, genericTemplateLtc }, // + { stringFactory, doubleFactory, genericTemplateLtc }, // + { stringFactory, longFactory, genericTemplateLtc }, // + { stringFactory, stringFactory, xGenericTemplateLtc }, // { stringFactory, stringFactory, jackson2JsonPersonTemplateLtc } }); }