From e51c56845b650e39d42a65db15c5b0db3a0e024e Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 17 Sep 2025 09:41:49 +0200 Subject: [PATCH 1/2] Prepare issue branch. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c52333368d..75f38e2755 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-redis - 4.0.0-SNAPSHOT + 4.0.0-GH-3219-SNAPSHOT Spring Data Redis Spring Data module for Redis From 83c98952f68c6157109b47c3f91204ac2e552407 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 17 Sep 2025 09:49:34 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Rename=20Jackson3=E2=80=A6=20classes=20to?= =?UTF-8?q?=20Jackson=20to=20align=20class=20naming.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Align class naming to drop the 3 from Jackson class names. Also, rename Jackson3ObjectReader and …Writer to JacksonReadeReader and JacksonJacksonWriter and rename the Jackson 2-based variants to Jackson2…. --- .../ROOT/pages/redis/hash-mappers.adoc | 13 +- .../redis/redis-repositories/mapping.adoc | 8 +- .../ROOT/pages/redis/redis-streams.adoc | 2 +- .../modules/ROOT/pages/redis/template.adoc | 2 +- .../data/redis/hash/Jackson2HashMapper.java | 2 +- ...HashMapper.java => JacksonHashMapper.java} | 90 +++++++------- .../GenericJackson2JsonRedisSerializer.java | 54 ++++----- ...=> GenericJacksonJsonRedisSerializer.java} | 114 +++++++++--------- .../Jackson2JsonRedisSerializer.java | 24 ++-- ...tReader.java => Jackson2ObjectReader.java} | 28 +++-- ...tWriter.java => Jackson2ObjectWriter.java} | 24 ++-- ...r.java => JacksonJsonRedisSerializer.java} | 42 +++---- .../redis/serializer/JacksonObjectReader.java | 22 ++-- .../redis/serializer/JacksonObjectWriter.java | 16 +-- .../core/AbstractOperationsTestParams.java | 4 +- .../core/ReactiveOperationsTestParams.java | 4 +- ...ts.java => JacksonCompatibilityTests.java} | 10 +- ... JacksonFlatteningCompatibilityTests.java} | 10 +- ...JacksonHashMapperFlatteningUnitTests.java} | 10 +- ...ksonHashMapperNonFlatteningUnitTests.java} | 10 +- ...s.java => JacksonHashMapperUnitTests.java} | 16 +-- ...cJacksonJsonRedisSerializerUnitTests.java} | 72 ++++++----- .../Jackson2JsonRedisSerializerTests.java | 2 +- .../collections/CollectionTestParams.java | 4 +- .../RedisPropertiesIntegrationTests.java | 6 +- 25 files changed, 294 insertions(+), 295 deletions(-) rename src/main/java/org/springframework/data/redis/hash/{Jackson3HashMapper.java => JacksonHashMapper.java} (84%) rename src/main/java/org/springframework/data/redis/serializer/{GenericJackson3JsonRedisSerializer.java => GenericJacksonJsonRedisSerializer.java} (80%) rename src/main/java/org/springframework/data/redis/serializer/{Jackson3ObjectReader.java => Jackson2ObjectReader.java} (61%) rename src/main/java/org/springframework/data/redis/serializer/{Jackson3ObjectWriter.java => Jackson2ObjectWriter.java} (64%) rename src/main/java/org/springframework/data/redis/serializer/{Jackson3JsonRedisSerializer.java => JacksonJsonRedisSerializer.java} (73%) rename src/test/java/org/springframework/data/redis/mapping/{Jackson3CompatibilityTests.java => JacksonCompatibilityTests.java} (78%) rename src/test/java/org/springframework/data/redis/mapping/{Jackson3FlatteningCompatibilityTests.java => JacksonFlatteningCompatibilityTests.java} (76%) rename src/test/java/org/springframework/data/redis/mapping/{Jackson3HashMapperFlatteningUnitTests.java => JacksonHashMapperFlatteningUnitTests.java} (84%) rename src/test/java/org/springframework/data/redis/mapping/{Jackson3HashMapperNonFlatteningUnitTests.java => JacksonHashMapperNonFlatteningUnitTests.java} (83%) rename src/test/java/org/springframework/data/redis/mapping/{Jackson3HashMapperUnitTests.java => JacksonHashMapperUnitTests.java} (95%) rename src/test/java/org/springframework/data/redis/serializer/{GenericJackson3JsonRedisSerializerUnitTests.java => GenericJacksonJsonRedisSerializerUnitTests.java} (85%) diff --git a/src/main/antora/modules/ROOT/pages/redis/hash-mappers.adoc b/src/main/antora/modules/ROOT/pages/redis/hash-mappers.adoc index 6f320d436b..c6961e280e 100644 --- a/src/main/antora/modules/ROOT/pages/redis/hash-mappers.adoc +++ b/src/main/antora/modules/ROOT/pages/redis/hash-mappers.adoc @@ -1,7 +1,10 @@ [[redis.hashmappers.root]] = Hash Mapping -Data can be stored by using various data structures within Redis. javadoc:org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer[] can convert objects in https://en.wikipedia.org/wiki/JSON[JSON] format. Ideally, JSON can be stored as a value by using plain keys. You can achieve a more sophisticated mapping of structured objects by using Redis hashes. Spring Data Redis offers various strategies for mapping data to hashes (depending on the use case): +Data can be stored by using various data structures within Redis. javadoc:org.springframework.data.redis.serializer.JacksonJsonRedisSerializer[] can convert objects in https://en.wikipedia.org/wiki/JSON[JSON] format. +Ideally, JSON can be stored as a value by using plain keys. +You can achieve a more sophisticated mapping of structured objects by using Redis hashes. +Spring Data Redis offers various strategies for mapping data to hashes (depending on the use case): * Direct mapping, by using javadoc:org.springframework.data.redis.core.HashOperations[] and a xref:redis.adoc#redis:serializer[serializer] * Using xref:repositories.adoc[Redis Repositories] @@ -16,7 +19,7 @@ Multiple implementations are available: * javadoc:org.springframework.data.redis.hash.BeanUtilsHashMapper[] using Spring's {spring-framework-javadoc}/org/springframework/beans/BeanUtils.html[BeanUtils]. * javadoc:org.springframework.data.redis.hash.ObjectHashMapper[] using xref:redis/redis-repositories/mapping.adoc[Object-to-Hash Mapping]. -* <> using https://github.com/FasterXML/jackson[FasterXML Jackson 3]. +* <> using https://github.com/FasterXML/jackson[FasterXML Jackson 3]. * <> (deprecated) using https://github.com/FasterXML/jackson[FasterXML Jackson 2]. The following example shows one way to implement hash mapping: @@ -52,10 +55,10 @@ public class HashMapping { ---- [[redis.hashmappers.jackson3]] -=== Jackson3HashMapper +=== JacksonHashMapper -javadoc:org.springframework.data.redis.hash.Jackson3HashMapper[] provides Redis Hash mapping for domain objects by using https://github.com/FasterXML/jackson[FasterXML Jackson 3]. -`Jackson3HashMapper` can map top-level properties as Hash field names and, optionally, flatten the structure. +javadoc:org.springframework.data.redis.hash.JacksonHashMapper[] provides Redis Hash mapping for domain objects by using https://github.com/FasterXML/jackson[FasterXML Jackson 3]. +`JacksonHashMapper` can map top-level properties as Hash field names and, optionally, flatten the structure. Simple types map to simple values. Complex types (nested objects, collections, maps, and so on) are represented as nested JSON. Flattening creates individual hash entries for all nested properties and resolves complex types into simple types, as far as possible. diff --git a/src/main/antora/modules/ROOT/pages/redis/redis-repositories/mapping.adoc b/src/main/antora/modules/ROOT/pages/redis/redis-repositories/mapping.adoc index 0d61f1239c..0404969a13 100644 --- a/src/main/antora/modules/ROOT/pages/redis/redis-repositories/mapping.adoc +++ b/src/main/antora/modules/ROOT/pages/redis/redis-repositories/mapping.adoc @@ -92,11 +92,11 @@ The following example shows two sample byte array converters: @WritingConverter public class AddressToBytesConverter implements Converter { - private final Jackson3JsonRedisSerializer
serializer; + private final JacksonJsonRedisSerializer
serializer; public AddressToBytesConverter() { - serializer = new Jackson3JsonRedisSerializer
(Address.class); + serializer = new JacksonJsonRedisSerializer
(Address.class); serializer.setObjectMapper(new ObjectMapper()); } @@ -109,11 +109,11 @@ public class AddressToBytesConverter implements Converter { @ReadingConverter public class BytesToAddressConverter implements Converter { - private final Jackson3JsonRedisSerializer
serializer; + private final JacksonJsonRedisSerializer
serializer; public BytesToAddressConverter() { - serializer = new Jackson3JsonRedisSerializer
(Address.class); + serializer = new JacksonJsonRedisSerializer
(Address.class); serializer.setObjectMapper(new ObjectMapper()); } diff --git a/src/main/antora/modules/ROOT/pages/redis/redis-streams.adoc b/src/main/antora/modules/ROOT/pages/redis/redis-streams.adoc index 0d71ee07f5..87a9bbdad4 100644 --- a/src/main/antora/modules/ROOT/pages/redis/redis-streams.adoc +++ b/src/main/antora/modules/ROOT/pages/redis/redis-streams.adoc @@ -291,7 +291,7 @@ You may provide a `HashMapper` suitable for your requirements when obtaining `St [source,java] ---- redisTemplate() - .opsForStream(new Jackson3HashMapper(true)) + .opsForStream(new JacksonHashMapper(true)) .add(record); <1> ---- <1> XADD user-logon * "firstname" "night" "@class" "com.example.User" "lastname" "angel" diff --git a/src/main/antora/modules/ROOT/pages/redis/template.adoc b/src/main/antora/modules/ROOT/pages/redis/template.adoc index 30f89e88e3..4eb55c7b53 100644 --- a/src/main/antora/modules/ROOT/pages/redis/template.adoc +++ b/src/main/antora/modules/ROOT/pages/redis/template.adoc @@ -365,7 +365,7 @@ Multiple implementations are available (including two that have been already men * javadoc:org.springframework.data.redis.serializer.JdkSerializationRedisSerializer[], which is used by default for javadoc:org.springframework.data.redis.cache.RedisCache[] and javadoc:org.springframework.data.redis.core.RedisTemplate[]. * the `StringRedisSerializer`. -However, one can use `OxmSerializer` for Object/XML mapping through Spring {spring-framework-docs}/data-access.html#oxm[OXM] support or javadoc:org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer[] or javadoc:org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer[] for storing data in https://en.wikipedia.org/wiki/JSON[JSON] format. +However, one can use `OxmSerializer` for Object/XML mapping through Spring {spring-framework-docs}/data-access.html#oxm[OXM] support or javadoc:org.springframework.data.redis.serializer.JacksonJsonRedisSerializer[] or javadoc:org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializer[] for storing data in https://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. diff --git a/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java b/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java index 6fa0ac272c..e53e169221 100644 --- a/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/Jackson2HashMapper.java @@ -144,7 +144,7 @@ * @author Mark Paluch * @author John Blum * @since 1.8 - * @deprecated since 4.0 in favor of {@link org.springframework.data.redis.hash.Jackson3HashMapper}. + * @deprecated since 4.0 in favor of {@link JacksonHashMapper}. */ @Deprecated(since = "4.0", forRemoval = true) public class Jackson2HashMapper implements HashMapper { diff --git a/src/main/java/org/springframework/data/redis/hash/Jackson3HashMapper.java b/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java similarity index 84% rename from src/main/java/org/springframework/data/redis/hash/Jackson3HashMapper.java rename to src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java index d59ed0fda5..fb305e6589 100644 --- a/src/main/java/org/springframework/data/redis/hash/Jackson3HashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java @@ -160,26 +160,26 @@ * @author Mark Paluch * @since 4.0 */ -public class Jackson3HashMapper implements HashMapper { +public class JacksonHashMapper implements HashMapper { - private static final Lazy sharedFlattening = Lazy - .of(() -> create(Jackson3HashMapperBuilder::flatten)); - private static final Lazy sharedHierarchical = Lazy - .of(() -> create(Jackson3HashMapperBuilder::hierarchical)); + private static final Lazy sharedFlattening = Lazy + .of(() -> create(JacksonHashMapperBuilder::flatten)); + private static final Lazy sharedHierarchical = Lazy + .of(() -> create(JacksonHashMapperBuilder::hierarchical)); private final ObjectMapper typingMapper; private final ObjectMapper untypedMapper; private final boolean flatten; /** - * Creates a new {@link Jackson3HashMapper} initialized with a custom Jackson {@link ObjectMapper}. + * Creates a new {@link JacksonHashMapper} initialized with a custom Jackson {@link ObjectMapper}. * * @param mapper Jackson {@link ObjectMapper} used to de/serialize hashed {@link Object objects}; must not be * {@literal null}. * @param flatten boolean used to configure whether JSON de/serialized {@link Object} properties will be un/flattened * using {@literal dot notation}, or whether to retain the hierarchical node structure created by Jackson. */ - public Jackson3HashMapper(ObjectMapper mapper, boolean flatten) { + public JacksonHashMapper(ObjectMapper mapper, boolean flatten) { Assert.notNull(mapper, "Mapper must not be null"); @@ -189,63 +189,61 @@ public Jackson3HashMapper(ObjectMapper mapper, boolean flatten) { } /** - * Returns a flattening {@link Jackson3HashMapper} using {@literal dot notation} for properties. + * Returns a flattening {@link JacksonHashMapper} using {@literal dot notation} for properties. * - * @return a flattening {@link Jackson3HashMapper} instance. + * @return a flattening {@link JacksonHashMapper} instance. */ - public static Jackson3HashMapper flattening() { + public static JacksonHashMapper flattening() { return sharedFlattening.get(); } /** - * Returns a {@link Jackson3HashMapper} retain the hierarchical node structure created by Jackson. + * Returns a {@link JacksonHashMapper} retain the hierarchical node structure created by Jackson. * - * @return a hierarchical {@link Jackson3HashMapper} instance. + * @return a hierarchical {@link JacksonHashMapper} instance. */ - public static Jackson3HashMapper hierarchical() { + public static JacksonHashMapper hierarchical() { return sharedHierarchical.get(); } /** - * Creates a new {@link Jackson3HashMapper} allowing further configuration through {@code configurer}. + * Creates a new {@link JacksonHashMapper} allowing further configuration through {@code configurer}. * - * @param configurer the configurer for {@link Jackson3HashMapperBuilder}. - * @return a new {@link Jackson3HashMapper} instance. + * @param configurer the configurer for {@link JacksonHashMapperBuilder}. + * @return a new {@link JacksonHashMapper} instance. */ - public static Jackson3HashMapper create( - Consumer> configurer) { + public static JacksonHashMapper create(Consumer> configurer) { Assert.notNull(configurer, "Builder configurer must not be null"); - Jackson3HashMapperBuilder builder = builder(); + JacksonHashMapperBuilder builder = builder(); configurer.accept(builder); return builder.build(); } /** - * Creates a {@link Jackson3HashMapperBuilder} to build a {@link Jackson3HashMapper} instance using - * {@link JsonMapper}. + * Creates a {@link JacksonHashMapperBuilder} to build a {@link JacksonHashMapper} instance using {@link JsonMapper}. * - * @return a {@link Jackson3HashMapperBuilder} to build a {@link Jackson3HashMapper} instance. + * @return a {@link JacksonHashMapperBuilder} to build a {@link JacksonHashMapper} instance. */ - public static Jackson3HashMapperBuilder builder() { + public static JacksonHashMapperBuilder builder() { return builder(JsonMapper::builder); } /** - * Creates a new {@link Jackson3HashMapperBuilder} to configure and build a {@link Jackson3HashMapper}. + * Creates a new {@link JacksonHashMapperBuilder} to configure and build a {@link JacksonHashMapper}. * * @param builderFactory factory to create a {@link MapperBuilder} for the {@link ObjectMapper}. * @param type of the {@link MapperBuilder} to use. - * @return a new {@link Jackson3HashMapperBuilder}. + * @return a new {@link JacksonHashMapperBuilder}. */ - public static >> Jackson3HashMapperBuilder builder( + public static >> JacksonHashMapperBuilder builder( Supplier builderFactory) { Assert.notNull(builderFactory, "MapperBuilder Factory must not be null"); - return new Jackson3HashMapperBuilder<>(builderFactory); + return new JacksonHashMapperBuilder<>(builderFactory); } /** @@ -272,7 +270,7 @@ public static void preconfigure(MapperBuilder toHash(@Nullable Object source) { JsonNode tree = this.typingMapper.valueToTree(source); - return this.flatten ? FlatEric.flatten(Jackson3AdapterFactory.INSTANCE, tree.properties()) + return this.flatten ? FlatEric.flatten(JacksonAdapterFactory.INSTANCE, tree.properties()) : this.untypedMapper.convertValue(tree, Map.class); } @@ -299,11 +297,11 @@ public Object fromHash(Map hash) { /** - * Builder to create a {@link Jackson3HashMapper} instance. + * Builder to create a {@link JacksonHashMapper} instance. * * @param type of the {@link MapperBuilder}. */ - public static class Jackson3HashMapperBuilder>> { + public static class JacksonHashMapperBuilder>> { private final Supplier builderFactory; @@ -313,7 +311,7 @@ public static class Jackson3HashMapperBuilder mapperBuilderCustomizer = builder -> {}; - private Jackson3HashMapperBuilder(Supplier builderFactory) { + private JacksonHashMapperBuilder(Supplier builderFactory) { this.builderFactory = builderFactory; } @@ -323,7 +321,7 @@ private Jackson3HashMapperBuilder(Supplier builderFactory) { * @return {@code this} builder. */ @Contract("-> this") - public Jackson3HashMapperBuilder flatten() { + public JacksonHashMapperBuilder flatten() { return flatten(true); } @@ -333,7 +331,7 @@ public Jackson3HashMapperBuilder flatten() { * @return {@code this} builder. */ @Contract("-> this") - public Jackson3HashMapperBuilder hierarchical() { + public JacksonHashMapperBuilder hierarchical() { return flatten(false); } @@ -347,7 +345,7 @@ public Jackson3HashMapperBuilder hierarchical() { * @return {@code this} builder. */ @Contract("_ -> this") - public Jackson3HashMapperBuilder flatten(boolean flatten) { + public JacksonHashMapperBuilder flatten(boolean flatten) { this.flatten = flatten; return this; } @@ -359,7 +357,7 @@ public Jackson3HashMapperBuilder flatten(boolean flatten) { * @return {@code this} builder. */ @Contract("-> this") - public Jackson3HashMapperBuilder jackson2CompatibilityMode() { + public JacksonHashMapperBuilder jackson2CompatibilityMode() { this.jackson2CompatibilityMode = true; return this; } @@ -371,7 +369,7 @@ public Jackson3HashMapperBuilder jackson2CompatibilityMode() { * @return {@code this} builder. */ @Contract("_ -> this") - public Jackson3HashMapperBuilder typeValidator(PolymorphicTypeValidator typeValidator) { + public JacksonHashMapperBuilder typeValidator(PolymorphicTypeValidator typeValidator) { Assert.notNull(typeValidator, "Type validator must not be null"); @@ -386,7 +384,7 @@ public Jackson3HashMapperBuilder typeValidator(PolymorphicTypeValidator typeV * @return {@code this} builder. */ @Contract("_ -> this") - public Jackson3HashMapperBuilder customize(Consumer mapperBuilderCustomizer) { + public JacksonHashMapperBuilder customize(Consumer mapperBuilderCustomizer) { Assert.notNull(mapperBuilderCustomizer, "JSON mapper customizer must not be null"); @@ -395,12 +393,12 @@ public Jackson3HashMapperBuilder customize(Consumer mapperBuilderCustomize } /** - * Build a new {@link Jackson3HashMapper} instance with the configured settings. + * Build a new {@link JacksonHashMapper} instance with the configured settings. * - * @return a new {@link Jackson3HashMapper} instance. + * @return a new {@link JacksonHashMapper} instance. */ @Contract("-> new") - public Jackson3HashMapper build() { + public JacksonHashMapper build() { B mapperBuilder = builderFactory.get(); @@ -409,7 +407,7 @@ public Jackson3HashMapper build() { mapperBuilderCustomizer.accept(mapperBuilder); - return new Jackson3HashMapper(mapperBuilder.build(), flatten); + return new JacksonHashMapper(mapperBuilder.build(), flatten); } private static TypeResolverBuilder getDefaultTyping(PolymorphicTypeValidator typeValidator, boolean flatten, @@ -564,14 +562,14 @@ public Calendar deserialize(JsonParser p, DeserializationContext ctxt) throws Ja } } - private enum Jackson3AdapterFactory implements FlatEric.JsonNodeAdapterFactory { + private enum JacksonAdapterFactory implements FlatEric.JsonNodeAdapterFactory { INSTANCE; @Override public FlatEric.JsonNodeAdapter adapt(Object node) { - return node instanceof FlatEric.JsonNodeAdapter na ? na : new Jackson3JsonNodeAdapter((JsonNode) node); + return node instanceof FlatEric.JsonNodeAdapter na ? na : new JacksonJsonNodeAdapter((JsonNode) node); } @Override @@ -580,7 +578,7 @@ public boolean isJsonNode(Object value) { } } - private record Jackson3JsonNodeAdapter(JsonNode node) implements FlatEric.JsonNodeAdapter { + private record JacksonJsonNodeAdapter(JsonNode node) implements FlatEric.JsonNodeAdapter { @Override public FlatEric.JsonNodeType getNodeType() { @@ -594,7 +592,7 @@ public boolean isArray() { @Override public Collection values() { - return node().valueStream().map(Jackson3JsonNodeAdapter::new).toList(); + return node().valueStream().map(JacksonJsonNodeAdapter::new).toList(); } @Override @@ -650,7 +648,7 @@ public boolean isObject() { @Override public Collection> properties() { return node().propertyStream() - .map(it -> Map.entry(it.getKey(), (FlatEric.JsonNodeAdapter) new Jackson3JsonNodeAdapter(it.getValue()))) + .map(it -> Map.entry(it.getKey(), (FlatEric.JsonNodeAdapter) new JacksonJsonNodeAdapter(it.getValue()))) .toList(); } 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 42fa6422d1..f120be3564 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializer.java @@ -60,27 +60,27 @@ * Generic Jackson 2-based {@link RedisSerializer} that maps {@link Object objects} to and from {@literal JSON} using * dynamic typing. *

- * {@literal JSON} reading and writing can be customized by configuring a {@link JacksonObjectReader} and - * {@link JacksonObjectWriter}. + * {@literal JSON} reading and writing can be customized by configuring a {@link Jackson2ObjectReader} and + * {@link Jackson2ObjectWriter}. * * @author Christoph Strobl * @author Mark Paluch * @author Mao Shuai * @author John Blum * @author Anne Lee - * @see org.springframework.data.redis.serializer.JacksonObjectReader - * @see org.springframework.data.redis.serializer.JacksonObjectWriter + * @see Jackson2ObjectReader + * @see Jackson2ObjectWriter * @see com.fasterxml.jackson.databind.ObjectMapper * @since 1.6 - * @deprecated since 4.0 in favor of {@link GenericJackson3JsonRedisSerializer} + * @deprecated since 4.0 in favor of {@link GenericJacksonJsonRedisSerializer} */ @SuppressWarnings("removal") @Deprecated(since = "4.0", forRemoval = true) public class GenericJackson2JsonRedisSerializer implements RedisSerializer { - private final JacksonObjectReader reader; + private final Jackson2ObjectReader reader; - private final JacksonObjectWriter writer; + private final Jackson2ObjectWriter writer; private final Lazy defaultTypingEnabled; @@ -109,27 +109,27 @@ public GenericJackson2JsonRedisSerializer() { * @see ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator, DefaultTyping, As) */ public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName) { - this(typeHintPropertyName, JacksonObjectReader.create(), JacksonObjectWriter.create()); + this(typeHintPropertyName, Jackson2ObjectReader.create(), Jackson2ObjectWriter.create()); } /** * Creates {@link GenericJackson2JsonRedisSerializer} initialized with an {@link ObjectMapper} configured for default - * typing using the given {@link String name} along with the given, required {@link JacksonObjectReader} and - * {@link JacksonObjectWriter} used to read/write {@link Object Objects} de/serialized as JSON. + * typing using the given {@link String name} along with the given, required {@link Jackson2ObjectReader} and + * {@link Jackson2ObjectWriter} used to read/write {@link Object Objects} de/serialized as JSON. *

* In case {@link String name} is {@literal empty} or {@literal null}, then {@link JsonTypeInfo.Id#CLASS} will be * used. * * @param typeHintPropertyName {@link String name} of the JSON property holding type information; can be * {@literal null}. - * @param reader {@link JacksonObjectReader} function to read objects using {@link ObjectMapper}. - * @param writer {@link JacksonObjectWriter} function to write objects using {@link ObjectMapper}. + * @param reader {@link Jackson2ObjectReader} function to read objects using {@link ObjectMapper}. + * @param writer {@link Jackson2ObjectWriter} function to write objects using {@link ObjectMapper}. * @see ObjectMapper#activateDefaultTypingAsProperty(PolymorphicTypeValidator, DefaultTyping, String) * @see ObjectMapper#activateDefaultTyping(PolymorphicTypeValidator, DefaultTyping, As) * @since 3.0 */ - public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName, JacksonObjectReader reader, - JacksonObjectWriter writer) { + public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName, Jackson2ObjectReader reader, + Jackson2ObjectWriter writer) { this(new ObjectMapper(), reader, writer, typeHintPropertyName); @@ -146,7 +146,7 @@ public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName, * @param mapper must not be {@literal null}. */ public GenericJackson2JsonRedisSerializer(ObjectMapper mapper) { - this(mapper, JacksonObjectReader.create(), JacksonObjectWriter.create()); + this(mapper, Jackson2ObjectReader.create(), Jackson2ObjectWriter.create()); } /** @@ -155,17 +155,17 @@ public GenericJackson2JsonRedisSerializer(ObjectMapper mapper) { * specific types. * * @param mapper must not be {@literal null}. - * @param reader the {@link JacksonObjectReader} function to read objects using {@link ObjectMapper}. - * @param writer the {@link JacksonObjectWriter} function to write objects using {@link ObjectMapper}. + * @param reader the {@link Jackson2ObjectReader} function to read objects using {@link ObjectMapper}. + * @param writer the {@link Jackson2ObjectWriter} function to write objects using {@link ObjectMapper}. * @since 3.0 */ - public GenericJackson2JsonRedisSerializer(ObjectMapper mapper, JacksonObjectReader reader, - JacksonObjectWriter writer) { + public GenericJackson2JsonRedisSerializer(ObjectMapper mapper, Jackson2ObjectReader reader, + Jackson2ObjectWriter writer) { this(mapper, reader, writer, null); } - private GenericJackson2JsonRedisSerializer(ObjectMapper mapper, JacksonObjectReader reader, - JacksonObjectWriter writer, @Nullable String typeHintPropertyName) { + private GenericJackson2JsonRedisSerializer(ObjectMapper mapper, Jackson2ObjectReader reader, + Jackson2ObjectWriter writer, @Nullable String typeHintPropertyName) { Assert.notNull(mapper, "ObjectMapper must not be null"); Assert.notNull(reader, "Reader must not be null"); @@ -466,9 +466,9 @@ public static class GenericJackson2JsonRedisSerializerBuilder { private @Nullable String typeHintPropertyName; - private JacksonObjectReader reader = JacksonObjectReader.create(); + private Jackson2ObjectReader reader = Jackson2ObjectReader.create(); - private JacksonObjectWriter writer = JacksonObjectWriter.create(); + private Jackson2ObjectWriter writer = Jackson2ObjectWriter.create(); private @Nullable ObjectMapper objectMapper; @@ -524,12 +524,12 @@ public GenericJackson2JsonRedisSerializerBuilder objectMapper(ObjectMapper objec } /** - * Configure {@link JacksonObjectReader}. + * Configure {@link Jackson2ObjectReader}. * * @param reader must not be {@literal null}. * @return this {@link GenericJackson2JsonRedisSerializer.GenericJackson2JsonRedisSerializerBuilder}. */ - public GenericJackson2JsonRedisSerializerBuilder reader(JacksonObjectReader reader) { + public GenericJackson2JsonRedisSerializerBuilder reader(Jackson2ObjectReader reader) { Assert.notNull(reader, "JacksonObjectReader must not be null"); @@ -538,12 +538,12 @@ public GenericJackson2JsonRedisSerializerBuilder reader(JacksonObjectReader read } /** - * Configure {@link JacksonObjectWriter}. + * Configure {@link Jackson2ObjectWriter}. * * @param writer must not be {@literal null}. * @return this {@link GenericJackson2JsonRedisSerializer.GenericJackson2JsonRedisSerializerBuilder}. */ - public GenericJackson2JsonRedisSerializerBuilder writer(JacksonObjectWriter writer) { + public GenericJackson2JsonRedisSerializerBuilder writer(Jackson2ObjectWriter writer) { Assert.notNull(writer, "JacksonObjectWriter must not be null"); diff --git a/src/main/java/org/springframework/data/redis/serializer/GenericJackson3JsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/GenericJacksonJsonRedisSerializer.java similarity index 80% rename from src/main/java/org/springframework/data/redis/serializer/GenericJackson3JsonRedisSerializer.java rename to src/main/java/org/springframework/data/redis/serializer/GenericJacksonJsonRedisSerializer.java index bcf6a3161e..363c19d73c 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericJackson3JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericJacksonJsonRedisSerializer.java @@ -64,20 +64,20 @@ /** * Generic Jackson 3-based {@link RedisSerializer} that maps {@link Object objects} to and from {@literal JSON}. *

- * {@literal JSON} reading and writing can be customized by configuring a {@link Jackson3ObjectReader} and - * {@link Jackson3ObjectWriter}. + * {@literal JSON} reading and writing can be customized by configuring a {@link JacksonObjectReader} and + * {@link JacksonObjectWriter}. * * @author Christoph Strobl - * @see Jackson3ObjectReader - * @see Jackson3ObjectWriter + * @see JacksonObjectReader + * @see JacksonObjectWriter * @see ObjectMapper * @since 4.0 */ -public class GenericJackson3JsonRedisSerializer implements RedisSerializer { +public class GenericJacksonJsonRedisSerializer implements RedisSerializer { - private final Jackson3ObjectReader reader; + private final JacksonObjectReader reader; - private final Jackson3ObjectWriter writer; + private final JacksonObjectWriter writer; private final Lazy defaultTypingEnabled; @@ -86,24 +86,24 @@ public class GenericJackson3JsonRedisSerializer implements RedisSerializer> configurer) { + public static GenericJacksonJsonRedisSerializer create( + Consumer> configurer) { Assert.notNull(configurer, "Builder configurer must not be null"); - GenericJackson3JsonRedisSerializerBuilder builder = builder(); + GenericJacksonJsonRedisSerializerBuilder builder = builder(); configurer.accept(builder); return builder.build(); } /** - * Creates a new {@link GenericJackson3JsonRedisSerializerBuilder} to configure and build a - * {@link GenericJackson3JsonRedisSerializer} using {@link JsonMapper}. + * Creates a new {@link GenericJacksonJsonRedisSerializerBuilder} to configure and build a + * {@link GenericJacksonJsonRedisSerializer} using {@link JsonMapper}. * - * @return a new {@link GenericJackson3JsonRedisSerializerBuilder}. + * @return a new {@link GenericJacksonJsonRedisSerializerBuilder}. */ - public static GenericJackson3JsonRedisSerializerBuilder builder() { + public static GenericJacksonJsonRedisSerializerBuilder builder() { return builder(JsonMapper::builder); } /** - * Creates a new {@link GenericJackson3JsonRedisSerializerBuilder} to configure and build a - * {@link GenericJackson3JsonRedisSerializer}. + * Creates a new {@link GenericJacksonJsonRedisSerializerBuilder} to configure and build a + * {@link GenericJacksonJsonRedisSerializer}. * * @param builderFactory factory to create a {@link MapperBuilder} for the {@link ObjectMapper}. * @param type of the {@link MapperBuilder} to use. - * @return a new {@link GenericJackson3JsonRedisSerializerBuilder}. + * @return a new {@link GenericJacksonJsonRedisSerializerBuilder}. */ - public static >> GenericJackson3JsonRedisSerializerBuilder builder( + public static >> GenericJacksonJsonRedisSerializerBuilder builder( Supplier builderFactory) { Assert.notNull(builderFactory, "MapperBuilder Factory must not be null"); - return new GenericJackson3JsonRedisSerializerBuilder<>(builderFactory); + return new GenericJacksonJsonRedisSerializerBuilder<>(builderFactory); } @Override @@ -254,14 +254,14 @@ private static Lazy getConfiguredTypeDeserializationPropertyName(ObjectM } /** - * {@link GenericJackson3JsonRedisSerializerBuilder} wraps around a {@link JsonMapper.Builder} providing dedicated + * {@link GenericJacksonJsonRedisSerializerBuilder} wraps around a {@link JsonMapper.Builder} providing dedicated * methods to configure aspects like {@link NullValue} serialization strategy for the resulting {@link ObjectMapper} - * to be used with {@link GenericJackson3JsonRedisSerializer} as well as potential Object/{@link Jackson3ObjectReader - * -reader} and {@link Jackson3ObjectWriter -writer} settings. + * to be used with {@link GenericJacksonJsonRedisSerializer} as well as potential Object/{@link JacksonObjectReader + * -reader} and {@link JacksonObjectWriter -writer} settings. * * @param type of the {@link MapperBuilder}. */ - public static class GenericJackson3JsonRedisSerializerBuilder>> { + public static class GenericJacksonJsonRedisSerializerBuilder>> { private final Supplier builderFactory; @@ -271,10 +271,10 @@ public static class GenericJackson3JsonRedisSerializerBuilder true).build(); private Consumer mapperBuilderCustomizer = (b) -> {}; - private Jackson3ObjectWriter writer = Jackson3ObjectWriter.create(); - private Jackson3ObjectReader reader = Jackson3ObjectReader.create(); + private JacksonObjectWriter writer = JacksonObjectWriter.create(); + private JacksonObjectReader reader = JacksonObjectReader.create(); - private GenericJackson3JsonRedisSerializerBuilder(Supplier builderFactory) { + private GenericJacksonJsonRedisSerializerBuilder(Supplier builderFactory) { this.builderFactory = builderFactory; } @@ -287,7 +287,7 @@ private GenericJackson3JsonRedisSerializerBuilder(Supplier builderFactory) { * @return this. */ @Contract("-> this") - public GenericJackson3JsonRedisSerializerBuilder enableSpringCacheNullValueSupport() { + public GenericJacksonJsonRedisSerializerBuilder enableSpringCacheNullValueSupport() { this.cacheNullValueSupportEnabled = true; return this; @@ -302,7 +302,7 @@ public GenericJackson3JsonRedisSerializerBuilder enableSpringCacheNullValueSu * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder enableSpringCacheNullValueSupport(String typePropertyName) { + public GenericJacksonJsonRedisSerializerBuilder enableSpringCacheNullValueSupport(String typePropertyName) { typePropertyName(typePropertyName); return enableSpringCacheNullValueSupport(); @@ -321,7 +321,7 @@ public GenericJackson3JsonRedisSerializerBuilder enableSpringCacheNullValueSu * "https://owasp.org/www-community/vulnerabilities/Deserialization_of_untrusted_data">https://owasp.org/www-community/vulnerabilities/Deserialization_of_untrusted_data */ @Contract("-> this") - public GenericJackson3JsonRedisSerializerBuilder enableUnsafeDefaultTyping() { + public GenericJacksonJsonRedisSerializerBuilder enableUnsafeDefaultTyping() { this.defaultTyping = true; return this; @@ -335,7 +335,7 @@ public GenericJackson3JsonRedisSerializerBuilder enableUnsafeDefaultTyping() * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder enableDefaultTyping(PolymorphicTypeValidator typeValidator) { + public GenericJacksonJsonRedisSerializerBuilder enableDefaultTyping(PolymorphicTypeValidator typeValidator) { typeValidator(typeValidator); @@ -350,7 +350,7 @@ public GenericJackson3JsonRedisSerializerBuilder enableDefaultTyping(Polymorp * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder typeValidator(PolymorphicTypeValidator typeValidator) { + public GenericJacksonJsonRedisSerializerBuilder typeValidator(PolymorphicTypeValidator typeValidator) { Assert.notNull(typeValidator, "Type validator must not be null"); @@ -364,7 +364,7 @@ public GenericJackson3JsonRedisSerializerBuilder typeValidator(PolymorphicTyp * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder typePropertyName(String typePropertyName) { + public GenericJacksonJsonRedisSerializerBuilder typePropertyName(String typePropertyName) { Assert.hasText(typePropertyName, "Property name must not be null or empty"); @@ -373,13 +373,13 @@ public GenericJackson3JsonRedisSerializerBuilder typePropertyName(String type } /** - * Configures the {@link Jackson3ObjectWriter}. + * Configures the {@link JacksonObjectWriter}. * * @param writer must not be {@literal null}. * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder writer(Jackson3ObjectWriter writer) { + public GenericJacksonJsonRedisSerializerBuilder writer(JacksonObjectWriter writer) { Assert.notNull(writer, "Jackson3ObjectWriter must not be null"); @@ -388,13 +388,13 @@ public GenericJackson3JsonRedisSerializerBuilder writer(Jackson3ObjectWriter } /** - * Configures the {@link Jackson3ObjectReader}. + * Configures the {@link JacksonObjectReader}. * * @param reader must not be {@literal null}. * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder reader(Jackson3ObjectReader reader) { + public GenericJacksonJsonRedisSerializerBuilder reader(JacksonObjectReader reader) { Assert.notNull(reader, "Jackson3ObjectReader must not be null"); @@ -409,7 +409,7 @@ public GenericJackson3JsonRedisSerializerBuilder reader(Jackson3ObjectReader * @return {@code this} builder. */ @Contract("_ -> this") - public GenericJackson3JsonRedisSerializerBuilder customize(Consumer mapperBuilderCustomizer) { + public GenericJacksonJsonRedisSerializerBuilder customize(Consumer mapperBuilderCustomizer) { Assert.notNull(mapperBuilderCustomizer, "JSON mapper configurer must not be null"); @@ -418,19 +418,19 @@ public GenericJackson3JsonRedisSerializerBuilder customize(Consumer mapper } /** - * Build a new {@link GenericJackson3JsonRedisSerializer} instance using the configured settings. + * Build a new {@link GenericJacksonJsonRedisSerializer} instance using the configured settings. * - * @return a new {@link GenericJackson3JsonRedisSerializer} instance. + * @return a new {@link GenericJacksonJsonRedisSerializer} instance. */ @Contract("-> new") - public GenericJackson3JsonRedisSerializer build() { + public GenericJacksonJsonRedisSerializer build() { B mapperBuilder = builderFactory.get(); if (cacheNullValueSupportEnabled) { String typePropertyName = StringUtils.hasText(this.typePropertyName) ? this.typePropertyName : "@class"; - mapperBuilder.addModules(new GenericJackson3RedisSerializerModule(() -> { + mapperBuilder.addModules(new GenericJacksonRedisSerializerModule(() -> { tools.jackson.databind.jsontype.TypeResolverBuilder defaultTyper = mapperBuilder.baseSettings() .getDefaultTyper(); if (defaultTyper instanceof StdTypeResolverBuilder stdTypeResolverBuilder) { @@ -442,7 +442,7 @@ public GenericJackson3JsonRedisSerializer build() { if (defaultTyping) { - GenericJackson3JsonRedisSerializer.TypeResolverBuilder resolver = new GenericJackson3JsonRedisSerializer.TypeResolverBuilder( + GenericJacksonJsonRedisSerializer.TypeResolverBuilder resolver = new GenericJacksonJsonRedisSerializer.TypeResolverBuilder( typeValidator, DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY, JsonTypeInfo.Id.CLASS, typePropertyName); mapperBuilder.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false) @@ -452,7 +452,7 @@ public GenericJackson3JsonRedisSerializer build() { mapperBuilderCustomizer.accept(mapperBuilder); - return new GenericJackson3JsonRedisSerializer(mapperBuilder.build(), reader, writer); + return new GenericJacksonJsonRedisSerializer(mapperBuilder.build(), reader, writer); } } @@ -570,11 +570,11 @@ public void serializeWithType(NullValue value, JsonGenerator gen, SerializationC } } - private static class GenericJackson3RedisSerializerModule extends JacksonModule { + private static class GenericJacksonRedisSerializerModule extends JacksonModule { private final Supplier classIdentifier; - GenericJackson3RedisSerializerModule(Supplier classIdentifier) { + GenericJacksonRedisSerializerModule(Supplier classIdentifier) { this.classIdentifier = classIdentifier; } 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 bdd0de0e18..84d99edbfe 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java @@ -35,13 +35,13 @@ * This serializer can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances. * Note:Null objects are serialized as empty arrays and vice versa. *

- * JSON reading and writing can be customized by configuring {@link JacksonObjectReader} respective - * {@link JacksonObjectWriter}. + * JSON reading and writing can be customized by configuring {@link Jackson2ObjectReader} respective + * {@link Jackson2ObjectWriter}. * * @author Thomas Darimont * @author Mark Paluch * @since 1.2 - * @deprecated since 4.0 in favor of {@link Jackson3JsonRedisSerializer}. + * @deprecated since 4.0 in favor of {@link JacksonJsonRedisSerializer}. */ @SuppressWarnings("removal") @Deprecated(since = "4.0", forRemoval = true) @@ -57,9 +57,9 @@ public class Jackson2JsonRedisSerializer implements RedisSerializer { private ObjectMapper mapper; - private final JacksonObjectReader reader; + private final Jackson2ObjectReader reader; - private final JacksonObjectWriter writer; + private final Jackson2ObjectWriter writer; /** * Creates a new {@link Jackson2JsonRedisSerializer} for the given target {@link Class}. @@ -93,8 +93,8 @@ public Jackson2JsonRedisSerializer(ObjectMapper mapper, Class type) { this.javaType = getJavaType(type); this.mapper = mapper; - this.reader = JacksonObjectReader.create(); - this.writer = JacksonObjectWriter.create(); + this.reader = Jackson2ObjectReader.create(); + this.writer = Jackson2ObjectWriter.create(); } /** @@ -105,7 +105,7 @@ public Jackson2JsonRedisSerializer(ObjectMapper mapper, Class type) { * @since 3.0 */ public Jackson2JsonRedisSerializer(ObjectMapper mapper, JavaType javaType) { - this(mapper, javaType, JacksonObjectReader.create(), JacksonObjectWriter.create()); + this(mapper, javaType, Jackson2ObjectReader.create(), Jackson2ObjectWriter.create()); } /** @@ -113,12 +113,12 @@ public Jackson2JsonRedisSerializer(ObjectMapper mapper, JavaType javaType) { * * @param mapper must not be {@literal null}. * @param javaType must not be {@literal null}. - * @param reader the {@link JacksonObjectReader} function to read objects using {@link ObjectMapper}. - * @param writer the {@link JacksonObjectWriter} function to write objects using {@link ObjectMapper}. + * @param reader the {@link Jackson2ObjectReader} function to read objects using {@link ObjectMapper}. + * @param writer the {@link Jackson2ObjectWriter} function to write objects using {@link ObjectMapper}. * @since 3.0 */ - public Jackson2JsonRedisSerializer(ObjectMapper mapper, JavaType javaType, JacksonObjectReader reader, - JacksonObjectWriter writer) { + public Jackson2JsonRedisSerializer(ObjectMapper mapper, JavaType javaType, Jackson2ObjectReader reader, + Jackson2ObjectWriter writer) { Assert.notNull(mapper, "ObjectMapper must not be null!"); Assert.notNull(reader, "Reader must not be null!"); diff --git a/src/main/java/org/springframework/data/redis/serializer/Jackson3ObjectReader.java b/src/main/java/org/springframework/data/redis/serializer/Jackson2ObjectReader.java similarity index 61% rename from src/main/java/org/springframework/data/redis/serializer/Jackson3ObjectReader.java rename to src/main/java/org/springframework/data/redis/serializer/Jackson2ObjectReader.java index 63de096f9b..cd69b13e2d 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson3ObjectReader.java +++ b/src/main/java/org/springframework/data/redis/serializer/Jackson2ObjectReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 the original author or authors. + * Copyright 2022-2025 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. @@ -15,22 +15,26 @@ */ package org.springframework.data.redis.serializer; -import tools.jackson.databind.JavaType; -import tools.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.io.InputStream; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; /** * Defines the contract for Object Mapping readers. Implementations of this interface can deserialize a given byte array * holding JSON to an Object considering the target type. *

* Reader functions can customize how the actual JSON is being deserialized by e.g. obtaining a customized - * {@link tools.jackson.databind.ObjectReader} applying serialization features, date formats, or views. + * {@link com.fasterxml.jackson.databind.ObjectReader} applying serialization features, date formats, or views. * - * @author Christoph Strobl * @author Mark Paluch - * @since 4.0 + * @since 3.0 + * @deprecated since 4.0 in favor of {@link JacksonObjectReader}. */ @FunctionalInterface -public interface Jackson3ObjectReader { +@Deprecated(since = "4.0", forRemoval = true) +public interface Jackson2ObjectReader { /** * Read an object graph from the given root JSON into a Java object considering the {@link JavaType}. @@ -39,16 +43,16 @@ public interface Jackson3ObjectReader { * @param source the JSON to deserialize. * @param type the Java target type * @return the deserialized Java object. + * @throws IOException if an I/O error or JSON deserialization error occurs. */ - Object read(ObjectMapper mapper, byte[] source, JavaType type); + Object read(ObjectMapper mapper, byte[] source, JavaType type) throws IOException; /** - * Create a default {@link Jackson3ObjectReader} delegating to - * {@link ObjectMapper#readValue(byte[], int, int, JavaType)}. + * Create a default {@link Jackson2ObjectReader} delegating to {@link ObjectMapper#readValue(InputStream, JavaType)}. * - * @return the default {@link Jackson3ObjectReader}. + * @return the default {@link Jackson2ObjectReader}. */ - static Jackson3ObjectReader create() { + static Jackson2ObjectReader create() { return (mapper, source, type) -> mapper.readValue(source, 0, source.length, type); } diff --git a/src/main/java/org/springframework/data/redis/serializer/Jackson3ObjectWriter.java b/src/main/java/org/springframework/data/redis/serializer/Jackson2ObjectWriter.java similarity index 64% rename from src/main/java/org/springframework/data/redis/serializer/Jackson3ObjectWriter.java rename to src/main/java/org/springframework/data/redis/serializer/Jackson2ObjectWriter.java index ecf133fbee..165c10c2fd 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson3ObjectWriter.java +++ b/src/main/java/org/springframework/data/redis/serializer/Jackson2ObjectWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 the original author or authors. + * Copyright 2022-2025 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. @@ -15,21 +15,24 @@ */ package org.springframework.data.redis.serializer; -import tools.jackson.databind.ObjectMapper; +import java.io.IOException; + +import com.fasterxml.jackson.databind.ObjectMapper; /** * Defines the contract for Object Mapping writers. Implementations of this interface can serialize a given Object to a * {@code byte[]} containing JSON. *

* Writer functions can customize how the actual JSON is being written by e.g. obtaining a customized - * {@link tools.jackson.databind.ObjectWriter} applying serialization features, date formats, or views. + * {@link com.fasterxml.jackson.databind.ObjectWriter} applying serialization features, date formats, or views. * - * @author Christoph Strobl * @author Mark Paluch - * @since 4.0 + * @since 3.0 + * @deprecated since 4.0 in favor of {@link JacksonObjectWriter}. */ @FunctionalInterface -public interface Jackson3ObjectWriter { +@Deprecated(since = "4.0", forRemoval = true) +public interface Jackson2ObjectWriter { /** * Write the object graph with the given root {@code source} as byte array. @@ -37,15 +40,16 @@ public interface Jackson3ObjectWriter { * @param mapper the object mapper to use. * @param source the root of the object graph to marshal. * @return a byte array containing the serialized object graph. + * @throws IOException if an I/O error or JSON serialization error occurs. */ - byte[] write(ObjectMapper mapper, Object source); + byte[] write(ObjectMapper mapper, Object source) throws IOException; /** - * Create a default {@link Jackson3ObjectWriter} delegating to {@link ObjectMapper#writeValueAsBytes(Object)}. + * Create a default {@link Jackson2ObjectWriter} delegating to {@link ObjectMapper#writeValueAsBytes(Object)}. * - * @return the default {@link Jackson3ObjectWriter}. + * @return the default {@link Jackson2ObjectWriter}. */ - static Jackson3ObjectWriter create() { + static Jackson2ObjectWriter create() { return ObjectMapper::writeValueAsBytes; } diff --git a/src/main/java/org/springframework/data/redis/serializer/Jackson3JsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java similarity index 73% rename from src/main/java/org/springframework/data/redis/serializer/Jackson3JsonRedisSerializer.java rename to src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java index 23c75a9443..bb4bd2e5a8 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson3JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java @@ -32,79 +32,79 @@ * This serializer can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances. * Note:Null objects are serialized as empty arrays and vice versa. *

- * JSON reading and writing can be customized by configuring {@link Jackson3ObjectReader} respective - * {@link Jackson3ObjectWriter}. + * JSON reading and writing can be customized by configuring {@link JacksonObjectReader} respective + * {@link JacksonObjectWriter}. * * @author Christoph Strobl * @author Thomas Darimont * @author Mark Paluch * @since 4.0 */ -public class Jackson3JsonRedisSerializer implements RedisSerializer { +public class JacksonJsonRedisSerializer implements RedisSerializer { private final JavaType javaType; private final ObjectMapper mapper; - private final Jackson3ObjectReader reader; + private final JacksonObjectReader reader; - private final Jackson3ObjectWriter writer; + private final JacksonObjectWriter writer; /** - * Creates a new {@link Jackson3JsonRedisSerializer} for the given target {@link Class}. + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link Class}. * * @param type must not be {@literal null}. */ - public Jackson3JsonRedisSerializer(Class type) { + public JacksonJsonRedisSerializer(Class type) { this(JsonMapper.shared(), type); } /** - * Creates a new {@link Jackson3JsonRedisSerializer} for the given target {@link JavaType}. + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link JavaType}. * * @param javaType must not be {@literal null}. */ - public Jackson3JsonRedisSerializer(JavaType javaType) { + public JacksonJsonRedisSerializer(JavaType javaType) { this(JsonMapper.shared(), javaType); } /** - * Creates a new {@link Jackson3JsonRedisSerializer} for the given target {@link Class}. + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link Class}. * * @param mapper must not be {@literal null}. * @param type must not be {@literal null}. */ - public Jackson3JsonRedisSerializer(ObjectMapper mapper, Class type) { + public JacksonJsonRedisSerializer(ObjectMapper mapper, Class type) { Assert.notNull(mapper, "ObjectMapper must not be null"); Assert.notNull(type, "Java type must not be null"); this.javaType = getJavaType(type); this.mapper = mapper; - this.reader = Jackson3ObjectReader.create(); - this.writer = Jackson3ObjectWriter.create(); + this.reader = JacksonObjectReader.create(); + this.writer = JacksonObjectWriter.create(); } /** - * Creates a new {@link Jackson3JsonRedisSerializer} for the given target {@link JavaType}. + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link JavaType}. * * @param mapper must not be {@literal null}. * @param javaType must not be {@literal null}. */ - public Jackson3JsonRedisSerializer(ObjectMapper mapper, JavaType javaType) { - this(mapper, javaType, Jackson3ObjectReader.create(), Jackson3ObjectWriter.create()); + public JacksonJsonRedisSerializer(ObjectMapper mapper, JavaType javaType) { + this(mapper, javaType, JacksonObjectReader.create(), JacksonObjectWriter.create()); } /** - * Creates a new {@link Jackson3JsonRedisSerializer} for the given target {@link JavaType}. + * Creates a new {@link JacksonJsonRedisSerializer} for the given target {@link JavaType}. * * @param mapper must not be {@literal null}. * @param javaType must not be {@literal null}. - * @param reader the {@link Jackson3ObjectReader} function to read objects using {@link ObjectMapper}. - * @param writer the {@link Jackson3ObjectWriter} function to write objects using {@link ObjectMapper}. + * @param reader the {@link JacksonObjectReader} function to read objects using {@link ObjectMapper}. + * @param writer the {@link JacksonObjectWriter} function to write objects using {@link ObjectMapper}. */ - public Jackson3JsonRedisSerializer(ObjectMapper mapper, JavaType javaType, Jackson3ObjectReader reader, - Jackson3ObjectWriter writer) { + public JacksonJsonRedisSerializer(ObjectMapper mapper, JavaType javaType, JacksonObjectReader reader, + JacksonObjectWriter writer) { Assert.notNull(mapper, "ObjectMapper must not be null"); Assert.notNull(reader, "Reader must not be null"); diff --git a/src/main/java/org/springframework/data/redis/serializer/JacksonObjectReader.java b/src/main/java/org/springframework/data/redis/serializer/JacksonObjectReader.java index 9da953f8dd..abe514ee45 100644 --- a/src/main/java/org/springframework/data/redis/serializer/JacksonObjectReader.java +++ b/src/main/java/org/springframework/data/redis/serializer/JacksonObjectReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2025 the original author or authors. + * Copyright 2025 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. @@ -15,25 +15,21 @@ */ package org.springframework.data.redis.serializer; -import java.io.IOException; -import java.io.InputStream; - -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.JavaType; +import tools.jackson.databind.ObjectMapper; /** * Defines the contract for Object Mapping readers. Implementations of this interface can deserialize a given byte array * holding JSON to an Object considering the target type. *

* Reader functions can customize how the actual JSON is being deserialized by e.g. obtaining a customized - * {@link com.fasterxml.jackson.databind.ObjectReader} applying serialization features, date formats, or views. + * {@link tools.jackson.databind.ObjectReader} applying serialization features, date formats, or views. * + * @author Christoph Strobl * @author Mark Paluch - * @since 3.0 - * @deprecated since 4.0 in favor of {@link Jackson3ObjectReader}. + * @since 4.0 */ @FunctionalInterface -@Deprecated(since = "4.0", forRemoval = true) public interface JacksonObjectReader { /** @@ -43,12 +39,12 @@ public interface JacksonObjectReader { * @param source the JSON to deserialize. * @param type the Java target type * @return the deserialized Java object. - * @throws IOException if an I/O error or JSON deserialization error occurs. */ - Object read(ObjectMapper mapper, byte[] source, JavaType type) throws IOException; + Object read(ObjectMapper mapper, byte[] source, JavaType type); /** - * Create a default {@link JacksonObjectReader} delegating to {@link ObjectMapper#readValue(InputStream, JavaType)}. + * Create a default {@link JacksonObjectReader} delegating to + * {@link ObjectMapper#readValue(byte[], int, int, JavaType)}. * * @return the default {@link JacksonObjectReader}. */ diff --git a/src/main/java/org/springframework/data/redis/serializer/JacksonObjectWriter.java b/src/main/java/org/springframework/data/redis/serializer/JacksonObjectWriter.java index 5d13b67b66..6ed481e8b7 100644 --- a/src/main/java/org/springframework/data/redis/serializer/JacksonObjectWriter.java +++ b/src/main/java/org/springframework/data/redis/serializer/JacksonObjectWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2025 the original author or authors. + * Copyright 2025 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. @@ -15,23 +15,20 @@ */ package org.springframework.data.redis.serializer; -import java.io.IOException; - -import com.fasterxml.jackson.databind.ObjectMapper; +import tools.jackson.databind.ObjectMapper; /** * Defines the contract for Object Mapping writers. Implementations of this interface can serialize a given Object to a * {@code byte[]} containing JSON. *

* Writer functions can customize how the actual JSON is being written by e.g. obtaining a customized - * {@link com.fasterxml.jackson.databind.ObjectWriter} applying serialization features, date formats, or views. + * {@link tools.jackson.databind.ObjectWriter} applying serialization features, date formats, or views. * + * @author Christoph Strobl * @author Mark Paluch - * @since 3.0 - * @deprecated since 4.0 in favor of {@link Jackson3ObjectWriter}. + * @since 4.0 */ @FunctionalInterface -@Deprecated(since = "4.0", forRemoval = true) public interface JacksonObjectWriter { /** @@ -40,9 +37,8 @@ public interface JacksonObjectWriter { * @param mapper the object mapper to use. * @param source the root of the object graph to marshal. * @return a byte array containing the serialized object graph. - * @throws IOException if an I/O error or JSON serialization error occurs. */ - byte[] write(ObjectMapper mapper, Object source) throws IOException; + byte[] write(ObjectMapper mapper, Object source); /** * Create a default {@link JacksonObjectWriter} delegating to {@link ObjectMapper#writeValueAsBytes(Object)}. 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 5726527114..338bd1cb2c 100644 --- a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java @@ -33,7 +33,7 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.GenericToStringSerializer; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer; +import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer; import org.springframework.data.redis.serializer.OxmSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.test.XstreamOxmSerializerSingleton; @@ -109,7 +109,7 @@ public static Collection testParams(RedisConnectionFactory connectionF jackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer); jackson2JsonPersonTemplate.afterPropertiesSet(); - Jackson3JsonRedisSerializer jackson3JsonSerializer = new Jackson3JsonRedisSerializer<>(Person.class); + JacksonJsonRedisSerializer jackson3JsonSerializer = new JacksonJsonRedisSerializer<>(Person.class); RedisTemplate jackson3JsonPersonTemplate = new RedisTemplate<>(); jackson3JsonPersonTemplate.setConnectionFactory(connectionFactory); jackson3JsonPersonTemplate.setValueSerializer(jackson3JsonSerializer); diff --git a/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java b/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java index 0df1458646..79eea2f989 100644 --- a/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java @@ -35,7 +35,7 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.GenericToStringSerializer; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer; +import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer; import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.redis.serializer.OxmSerializer; import org.springframework.data.redis.serializer.RedisSerializationContext; @@ -101,7 +101,7 @@ RedisSerializationContext. newSerializationContext(jdkSerializat ReactiveRedisTemplate jackson2JsonPersonTemplate = new ReactiveRedisTemplate( lettuceConnectionFactory, RedisSerializationContext.fromSerializer(jackson2JsonSerializer)); - Jackson3JsonRedisSerializer jackson3JsonSerializer = new Jackson3JsonRedisSerializer<>(Person.class); + JacksonJsonRedisSerializer jackson3JsonSerializer = new JacksonJsonRedisSerializer<>(Person.class); ReactiveRedisTemplate jackson3JsonPersonTemplate = new ReactiveRedisTemplate( lettuceConnectionFactory, RedisSerializationContext.fromSerializer(jackson3JsonSerializer)); diff --git a/src/test/java/org/springframework/data/redis/mapping/Jackson3CompatibilityTests.java b/src/test/java/org/springframework/data/redis/mapping/JacksonCompatibilityTests.java similarity index 78% rename from src/test/java/org/springframework/data/redis/mapping/Jackson3CompatibilityTests.java rename to src/test/java/org/springframework/data/redis/mapping/JacksonCompatibilityTests.java index 5c4d60a741..9ff180b8f7 100644 --- a/src/test/java/org/springframework/data/redis/mapping/Jackson3CompatibilityTests.java +++ b/src/test/java/org/springframework/data/redis/mapping/JacksonCompatibilityTests.java @@ -20,21 +20,21 @@ import java.util.Map; import org.springframework.data.redis.hash.Jackson2HashMapper; -import org.springframework.data.redis.hash.Jackson3HashMapper; +import org.springframework.data.redis.hash.JacksonHashMapper; /** - * TCK-style tests to assert {@link Jackson3HashMapper} interoperability with {@link Jackson2HashMapper} in hierarchical + * TCK-style tests to assert {@link JacksonHashMapper} interoperability with {@link Jackson2HashMapper} in hierarchical * mode. * * @author Christoph Strobl */ @SuppressWarnings("removal") -class Jackson3CompatibilityTests extends Jackson3HashMapperUnitTests { +class JacksonCompatibilityTests extends JacksonHashMapperUnitTests { private final Jackson2HashMapper jackson2HashMapper; - Jackson3CompatibilityTests() { - super(Jackson3HashMapper.builder().jackson2CompatibilityMode().build()); + JacksonCompatibilityTests() { + super(JacksonHashMapper.builder().jackson2CompatibilityMode().build()); this.jackson2HashMapper = new Jackson2HashMapper(false); } diff --git a/src/test/java/org/springframework/data/redis/mapping/Jackson3FlatteningCompatibilityTests.java b/src/test/java/org/springframework/data/redis/mapping/JacksonFlatteningCompatibilityTests.java similarity index 76% rename from src/test/java/org/springframework/data/redis/mapping/Jackson3FlatteningCompatibilityTests.java rename to src/test/java/org/springframework/data/redis/mapping/JacksonFlatteningCompatibilityTests.java index d759991848..c61a41fa1d 100644 --- a/src/test/java/org/springframework/data/redis/mapping/Jackson3FlatteningCompatibilityTests.java +++ b/src/test/java/org/springframework/data/redis/mapping/JacksonFlatteningCompatibilityTests.java @@ -20,21 +20,21 @@ import java.util.Map; import org.springframework.data.redis.hash.Jackson2HashMapper; -import org.springframework.data.redis.hash.Jackson3HashMapper; +import org.springframework.data.redis.hash.JacksonHashMapper; /** - * TCK-style tests to assert {@link Jackson3HashMapper} interoperability with {@link Jackson2HashMapper} in flattening + * TCK-style tests to assert {@link JacksonHashMapper} interoperability with {@link Jackson2HashMapper} in flattening * mode. * * @author Christoph Strobl */ @SuppressWarnings("removal") -class Jackson3FlatteningCompatibilityTests extends Jackson3HashMapperUnitTests { +class JacksonFlatteningCompatibilityTests extends JacksonHashMapperUnitTests { private final Jackson2HashMapper jackson2HashMapper; - Jackson3FlatteningCompatibilityTests() { - super(Jackson3HashMapper.builder().jackson2CompatibilityMode().flatten().build()); + JacksonFlatteningCompatibilityTests() { + super(JacksonHashMapper.builder().jackson2CompatibilityMode().flatten().build()); this.jackson2HashMapper = new Jackson2HashMapper(true); } diff --git a/src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperFlatteningUnitTests.java b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperFlatteningUnitTests.java similarity index 84% rename from src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperFlatteningUnitTests.java rename to src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperFlatteningUnitTests.java index fe23e9f430..734eac6a22 100644 --- a/src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperFlatteningUnitTests.java +++ b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperFlatteningUnitTests.java @@ -23,18 +23,18 @@ import org.junit.jupiter.api.Test; -import org.springframework.data.redis.hash.Jackson3HashMapper; +import org.springframework.data.redis.hash.JacksonHashMapper; /** - * Unit tests for {@link Jackson3HashMapper} using flattening mode. + * Unit tests for {@link JacksonHashMapper} using flattening mode. * * @author Christoph Strobl * @author John Blum */ -class Jackson3HashMapperFlatteningUnitTests extends Jackson3HashMapperUnitTests { +class JacksonHashMapperFlatteningUnitTests extends JacksonHashMapperUnitTests { - Jackson3HashMapperFlatteningUnitTests() { - super(Jackson3HashMapper.flattening()); + JacksonHashMapperFlatteningUnitTests() { + super(JacksonHashMapper.flattening()); } @Test // GH-2593 diff --git a/src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperNonFlatteningUnitTests.java b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperNonFlatteningUnitTests.java similarity index 83% rename from src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperNonFlatteningUnitTests.java rename to src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperNonFlatteningUnitTests.java index 8b70a3ee83..2e021eecd0 100644 --- a/src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperNonFlatteningUnitTests.java +++ b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperNonFlatteningUnitTests.java @@ -23,18 +23,18 @@ import org.junit.jupiter.api.Test; -import org.springframework.data.redis.hash.Jackson3HashMapper; +import org.springframework.data.redis.hash.JacksonHashMapper; /** - * Unit tests for {@link Jackson3HashMapper} using hierarchical mode. + * Unit tests for {@link JacksonHashMapper} using hierarchical mode. * * @author Christoph Strobl * @author John Blum */ -class Jackson3HashMapperNonFlatteningUnitTests extends Jackson3HashMapperUnitTests { +class JacksonHashMapperNonFlatteningUnitTests extends JacksonHashMapperUnitTests { - Jackson3HashMapperNonFlatteningUnitTests() { - super(Jackson3HashMapper.hierarchical()); + JacksonHashMapperNonFlatteningUnitTests() { + super(JacksonHashMapper.hierarchical()); } @Test // GH-2593 diff --git a/src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperUnitTests.java b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperUnitTests.java similarity index 95% rename from src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperUnitTests.java rename to src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperUnitTests.java index db28ec61eb..889a411de2 100644 --- a/src/test/java/org/springframework/data/redis/mapping/Jackson3HashMapperUnitTests.java +++ b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperUnitTests.java @@ -39,25 +39,25 @@ import org.springframework.data.redis.Address; import org.springframework.data.redis.Person; import org.springframework.data.redis.hash.HashMapper; -import org.springframework.data.redis.hash.Jackson3HashMapper; +import org.springframework.data.redis.hash.JacksonHashMapper; /** - * Support class for {@link Jackson3HashMapper} unit tests. + * Support class for {@link JacksonHashMapper} unit tests. * * @author Christoph Strobl * @author Mark Paluch * @author John Blum */ -abstract class Jackson3HashMapperUnitTests extends AbstractHashMapperTests { +abstract class JacksonHashMapperUnitTests extends AbstractHashMapperTests { - private final Jackson3HashMapper mapper; + private final JacksonHashMapper mapper; - Jackson3HashMapperUnitTests(Jackson3HashMapper mapper) { + JacksonHashMapperUnitTests(JacksonHashMapper mapper) { this.mapper = mapper; } - Jackson3HashMapper getMapper() { + JacksonHashMapper getMapper() { return this.mapper; } @@ -222,7 +222,7 @@ void enumsShouldBeTreatedCorrectly() { @Test // GH-3292 void configuresObjectMapper() { - Jackson3HashMapper serializer = Jackson3HashMapper.builder(() -> new ObjectMapper().rebuild()) + JacksonHashMapper serializer = JacksonHashMapper.builder(() -> new ObjectMapper().rebuild()) .customize(mb -> mb.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)).build(); assertThat(serializer).isNotNull(); @@ -231,7 +231,7 @@ void configuresObjectMapper() { @Test // GH-3292 void configuresJsonMapper() { - Jackson3HashMapper serializer = Jackson3HashMapper.create(b -> { + JacksonHashMapper serializer = JacksonHashMapper.create(b -> { b.customize(mb -> mb.enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)); }); diff --git a/src/test/java/org/springframework/data/redis/serializer/GenericJackson3JsonRedisSerializerUnitTests.java b/src/test/java/org/springframework/data/redis/serializer/GenericJacksonJsonRedisSerializerUnitTests.java similarity index 85% rename from src/test/java/org/springframework/data/redis/serializer/GenericJackson3JsonRedisSerializerUnitTests.java rename to src/test/java/org/springframework/data/redis/serializer/GenericJacksonJsonRedisSerializerUnitTests.java index 4b017ec246..bc8b86b03c 100644 --- a/src/test/java/org/springframework/data/redis/serializer/GenericJackson3JsonRedisSerializerUnitTests.java +++ b/src/test/java/org/springframework/data/redis/serializer/GenericJacksonJsonRedisSerializerUnitTests.java @@ -15,9 +15,7 @@ */ package org.springframework.data.redis.serializer; -import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.*; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -57,18 +55,18 @@ import com.fasterxml.jackson.annotation.JsonView; /** - * Unit tests for {@link GenericJackson3JsonRedisSerializer}. + * Unit tests for {@link GenericJacksonJsonRedisSerializer}. * * @author Christoph Strobl * @author Mark Paluch * @author John Blum */ -class GenericJackson3JsonRedisSerializerUnitTests { +class GenericJacksonJsonRedisSerializerUnitTests { private static final SimpleObject SIMPLE_OBJECT = new SimpleObject(1L); private static final ComplexObject COMPLEX_OBJECT = new ComplexObject("steelheart", SIMPLE_OBJECT); - private final GenericJackson3JsonRedisSerializer serializer = GenericJackson3JsonRedisSerializer + private final GenericJacksonJsonRedisSerializer serializer = GenericJacksonJsonRedisSerializer .create(it -> it.enableSpringCacheNullValueSupport().enableUnsafeDefaultTyping()); @Test // DATAREDIS-392, GH-2878 @@ -94,7 +92,7 @@ void deserializeShouldReturnNullWhenSouceIsEmptyArray() { @Test // DATAREDIS-392 void deserializeShouldBeAbleToRestoreSimpleObjectAfterSerialization() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; assertThat((SimpleObject) serializer.deserialize(serializer.serialize(SIMPLE_OBJECT))).isEqualTo(SIMPLE_OBJECT); } @@ -102,7 +100,7 @@ void deserializeShouldBeAbleToRestoreSimpleObjectAfterSerialization() { @Test // DATAREDIS-392 void deserializeShouldBeAbleToRestoreComplexObjectAfterSerialization() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; assertThat((ComplexObject) serializer.deserialize(serializer.serialize(COMPLEX_OBJECT))).isEqualTo(COMPLEX_OBJECT); } @@ -115,7 +113,7 @@ void serializeShouldThrowSerializationExceptionProcessingError() { .thenThrow(JacksonIOException.construct(new IOException("doesn't work"))); assertThatExceptionOfType(SerializationException.class) - .isThrownBy(() -> new GenericJackson3JsonRedisSerializer(objectMapperMock).serialize(SIMPLE_OBJECT)); + .isThrownBy(() -> new GenericJacksonJsonRedisSerializer(objectMapperMock).serialize(SIMPLE_OBJECT)); } @Test // DATAREDIS-392 @@ -125,13 +123,13 @@ void deserializeShouldThrowSerializationExceptionProcessingError() throws IOExce when(objectMapperMock.readValue(any(byte[].class), any(Class.class))).thenThrow(new StreamReadException("conflux")); assertThatExceptionOfType(SerializationException.class) - .isThrownBy(() -> new GenericJackson3JsonRedisSerializer(objectMapperMock).deserialize(new byte[] { 1 })); + .isThrownBy(() -> new GenericJacksonJsonRedisSerializer(objectMapperMock).deserialize(new byte[] { 1 })); } @Test // DATAREDIS-553, DATAREDIS-865 void shouldSerializeNullValueSoThatItCanBeDeserializedWithDefaultTypingEnabled() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; serializeAndDeserializeNullValue(serializer); } @@ -139,7 +137,7 @@ void shouldSerializeNullValueSoThatItCanBeDeserializedWithDefaultTypingEnabled() @Test // DATAREDIS-865 void shouldSerializeNullValueWithCustomObjectMapper() { - GenericJackson3JsonRedisSerializer serializer = GenericJackson3JsonRedisSerializer.create(configHelper -> { + GenericJacksonJsonRedisSerializer serializer = GenericJacksonJsonRedisSerializer.create(configHelper -> { configHelper.enableSpringCacheNullValueSupport() // .customize(mapperBuilder -> { mapperBuilder.activateDefaultTypingAsProperty(BasicPolymorphicTypeValidator.builder().build(), @@ -153,7 +151,7 @@ void shouldSerializeNullValueWithCustomObjectMapper() { @Test // GH-1566 void deserializeShouldBeAbleToRestoreFinalObjectAfterSerialization() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; FinalObject source = new FinalObject(); source.longValue = 1L; @@ -162,8 +160,8 @@ void deserializeShouldBeAbleToRestoreFinalObjectAfterSerialization() { assertThat(serializer.deserialize(serializer.serialize(source))).isEqualTo(source); assertThat(serializer.deserialize( - ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$FinalObject\",\"longValue\":1,\"myArray\":[1,2,3],\n" - + "\"simpleObject\":{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$SimpleObject\",\"longValue\":2}}") + ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$FinalObject\",\"longValue\":1,\"myArray\":[1,2,3],\n" + + "\"simpleObject\":{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$SimpleObject\",\"longValue\":2}}") .getBytes())) .isEqualTo(source); } @@ -171,9 +169,9 @@ void deserializeShouldBeAbleToRestoreFinalObjectAfterSerialization() { @Test // GH-2361 void shouldDeserializePrimitiveArrayWithoutTypeHint() { - GenericJackson3JsonRedisSerializer gs = serializer; + GenericJacksonJsonRedisSerializer gs = serializer; CountAndArray result = (CountAndArray) gs.deserialize( - ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$CountAndArray\", \"count\":1, \"available\":[0,1]}") + ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$CountAndArray\", \"count\":1, \"available\":[0,1]}") .getBytes()); assertThat(result.getCount()).isEqualTo(1); @@ -183,7 +181,7 @@ void shouldDeserializePrimitiveArrayWithoutTypeHint() { @Test // GH-2322 void readsToMapForNonDefaultTyping() { - GenericJackson3JsonRedisSerializer serializer = new GenericJackson3JsonRedisSerializer(JsonMapper.shared()); + GenericJacksonJsonRedisSerializer serializer = new GenericJacksonJsonRedisSerializer(JsonMapper.shared()); User user = new User(); user.email = "walter@heisenberg.com"; @@ -204,7 +202,7 @@ void shouldConsiderWriter() { user.id = 42; user.name = "Walter White"; - GenericJackson3JsonRedisSerializer serializer = GenericJackson3JsonRedisSerializer.create(configHelper -> { + GenericJacksonJsonRedisSerializer serializer = GenericJacksonJsonRedisSerializer.create(configHelper -> { configHelper.writer((mapper, source) -> mapper.writerWithView(Views.Basic.class).writeValueAsBytes(source)); }); @@ -221,7 +219,7 @@ void shouldConsiderReader() { user.id = 42; user.name = "Walter White"; - GenericJackson3JsonRedisSerializer serializer = GenericJackson3JsonRedisSerializer.create(configHelper -> { + GenericJacksonJsonRedisSerializer serializer = GenericJacksonJsonRedisSerializer.create(configHelper -> { configHelper.enableUnsafeDefaultTyping(); configHelper.reader((mapper, source, type) -> { @@ -247,9 +245,9 @@ void shouldConsiderReader() { @Test // GH-2361 void shouldDeserializePrimitiveWrapperArrayWithoutTypeHint() { - GenericJackson3JsonRedisSerializer gs = this.serializer; + GenericJacksonJsonRedisSerializer gs = this.serializer; CountAndArray result = (CountAndArray) gs.deserialize( - ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$CountAndArray\", \"count\":1, \"arrayOfPrimitiveWrapper\":[0,1]}") + ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$CountAndArray\", \"count\":1, \"arrayOfPrimitiveWrapper\":[0,1]}") .getBytes()); assertThat(result.getCount()).isEqualTo(1); @@ -259,7 +257,7 @@ void shouldDeserializePrimitiveWrapperArrayWithoutTypeHint() { @Test // GH-2361 void doesNotIncludeTypingForPrimitiveArrayWrappers() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; WithWrapperTypes source = new WithWrapperTypes(); source.primitiveWrapper = new AtomicReference<>(); @@ -283,7 +281,7 @@ void doesNotIncludeTypingForPrimitiveArrayWrappers() { @Test // GH-2361 void doesNotIncludeTypingForPrimitiveWrappers() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; WithWrapperTypes source = new WithWrapperTypes(); source.primitiveWrapper = new AtomicReference<>(123L); @@ -305,7 +303,7 @@ void doesNotIncludeTypingForPrimitiveWrappers() { @Test // GH-2361 void includesTypingForWrappedObjectTypes() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; SimpleObject simpleObject = new SimpleObject(100L); WithWrapperTypes source = new WithWrapperTypes(); @@ -315,7 +313,7 @@ void includesTypingForWrappedObjectTypes() { assertThat(new String(serializedValue)) // .contains( - "\"simpleObjectWrapper\":{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$SimpleObject\",\"longValue\":100}"); + "\"simpleObjectWrapper\":{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$SimpleObject\",\"longValue\":100}"); assertThat(serializer.deserialize(serializedValue)) // .isInstanceOf(WithWrapperTypes.class) // @@ -328,7 +326,7 @@ void includesTypingForWrappedObjectTypes() { @Test // GH-2396 void verifySerializeUUIDIntoBytes() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; UUID source = UUID.fromString("730145fe-324d-4fb1-b12f-60b89a045730"); assertThat(serializer.serialize(source)).isEqualTo(("\"" + source + "\"").getBytes(StandardCharsets.UTF_8)); @@ -337,7 +335,7 @@ void verifySerializeUUIDIntoBytes() { @Test // GH-2396 void deserializesUUIDFromBytes() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; UUID deserializedUuid = serializer .deserialize("\"730145fe-324d-4fb1-b12f-60b89a045730\"".getBytes(StandardCharsets.UTF_8), UUID.class); @@ -347,7 +345,7 @@ void deserializesUUIDFromBytes() { @Test // GH-2396 void serializesEnumIntoBytes() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; assertThat(serializer.serialize(EnumType.ONE)).isEqualTo(("\"ONE\"").getBytes(StandardCharsets.UTF_8)); } @@ -355,7 +353,7 @@ void serializesEnumIntoBytes() { @Test // GH-2396 void deserializesEnumFromBytes() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; assertThat(serializer.deserialize("\"TWO\"".getBytes(StandardCharsets.UTF_8), EnumType.class)) .isEqualTo(EnumType.TWO); @@ -364,23 +362,23 @@ void deserializesEnumFromBytes() { @Test // GH-2396 void serializesJavaTimeIntoBytes() { - GenericJackson3JsonRedisSerializer serializer = this.serializer; + GenericJacksonJsonRedisSerializer serializer = this.serializer; WithJsr310 source = new WithJsr310(); source.myDate = LocalDate.of(2022, 9, 2); byte[] serialized = serializer.serialize(source); assertThat(serialized).isEqualTo( - ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$WithJsr310\",\"myDate\":\"2022-09-02\"}") + ("{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$WithJsr310\",\"myDate\":\"2022-09-02\"}") .getBytes(StandardCharsets.UTF_8)); } @Test // GH-2396 void deserializesJavaTimeFromBytes() { - GenericJackson3JsonRedisSerializer serializer = new GenericJackson3JsonRedisSerializer(JsonMapper.shared()); + GenericJacksonJsonRedisSerializer serializer = new GenericJacksonJsonRedisSerializer(JsonMapper.shared()); - byte[] source = "{\"@class\":\"org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializerUnitTests$WithJsr310\",\"myDate\":\"2022-09-02\"}" + byte[] source = "{\"@class\":\"org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializerUnitTests$WithJsr310\",\"myDate\":\"2022-09-02\"}" .getBytes(StandardCharsets.UTF_8); assertThat(serializer.deserialize(source, WithJsr310.class).myDate).isEqualTo(LocalDate.of(2022, 9, 2)); } @@ -388,7 +386,7 @@ void deserializesJavaTimeFromBytes() { @Test // GH-3292 void configuresObjectMapper() { - GenericJackson3JsonRedisSerializer serializer = GenericJackson3JsonRedisSerializer + GenericJacksonJsonRedisSerializer serializer = GenericJacksonJsonRedisSerializer .builder(() -> new ObjectMapper().rebuild()) .customize(mb -> mb.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)).build(); @@ -398,14 +396,14 @@ void configuresObjectMapper() { @Test // GH-3292 void configuresJsonMapper() { - GenericJackson3JsonRedisSerializer serializer = GenericJackson3JsonRedisSerializer.create(b -> { + GenericJacksonJsonRedisSerializer serializer = GenericJacksonJsonRedisSerializer.create(b -> { b.customize(mb -> mb.enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)); }); assertThat(serializer).isNotNull(); } - private static void serializeAndDeserializeNullValue(GenericJackson3JsonRedisSerializer serializer) { + private static void serializeAndDeserializeNullValue(GenericJacksonJsonRedisSerializer serializer) { NullValue nv = BeanUtils.instantiateClass(NullValue.class); @@ -416,7 +414,7 @@ private static void serializeAndDeserializeNullValue(GenericJackson3JsonRedisSer assertThat(deserializedValue).isInstanceOf(NullValue.class); } - private @Nullable TypeResolverBuilder extractTypeResolver(GenericJackson3JsonRedisSerializer serializer) { + private @Nullable TypeResolverBuilder extractTypeResolver(GenericJacksonJsonRedisSerializer serializer) { ObjectMapper mapper = (ObjectMapper) getField(serializer, "mapper"); return mapper.serializationConfig() diff --git a/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java b/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java index da98eff85d..bcbc5b05a8 100644 --- a/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java +++ b/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java @@ -74,7 +74,7 @@ void testJackson2JsonSerilizerThrowsExceptionWhenSettingNullObjectMapper() { void shouldConsiderWriter() { serializer = new Jackson2JsonRedisSerializer<>(new ObjectMapper(), - TypeFactory.defaultInstance().constructType(Person.class), JacksonObjectReader.create(), + TypeFactory.defaultInstance().constructType(Person.class), Jackson2ObjectReader.create(), (mapper, source) -> "foo".getBytes()); Person person = new PersonObjectFactory().instance(); assertThat(serializer.serialize(person)).isEqualTo("foo".getBytes()); 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 fcf42c0f07..89c183e715 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 @@ -31,7 +31,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer; +import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer; import org.springframework.data.redis.serializer.OxmSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.test.XstreamOxmSerializerSingleton; @@ -49,7 +49,7 @@ public static Collection testParams() { OxmSerializer serializer = XstreamOxmSerializerSingleton.getInstance(); Jackson2JsonRedisSerializer jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class); - Jackson3JsonRedisSerializer jackson3JsonSerializer = new Jackson3JsonRedisSerializer<>(Person.class); + JacksonJsonRedisSerializer jackson3JsonSerializer = new JacksonJsonRedisSerializer<>(Person.class); StringRedisSerializer stringSerializer = StringRedisSerializer.UTF_8; // create Jedis Factory diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java index 993a888006..bb5ae1ae64 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java @@ -42,7 +42,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.Jackson3JsonRedisSerializer; +import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer; import org.springframework.data.redis.serializer.OxmSerializer; import org.springframework.data.redis.test.XstreamOxmSerializerSingleton; import org.springframework.data.redis.test.extension.RedisStandalone; @@ -196,8 +196,8 @@ public static Collection testParams() { Jackson2JsonRedisSerializer jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class); Jackson2JsonRedisSerializer jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<>( String.class); - Jackson3JsonRedisSerializer jackson3JsonSerializer = new Jackson3JsonRedisSerializer<>(Person.class); - Jackson3JsonRedisSerializer jackson3JsonStringSerializer = new Jackson3JsonRedisSerializer<>( + JacksonJsonRedisSerializer jackson3JsonSerializer = new JacksonJsonRedisSerializer<>(Person.class); + JacksonJsonRedisSerializer jackson3JsonStringSerializer = new JacksonJsonRedisSerializer<>( String.class); // create Jedis Factory