diff --git a/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java b/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java index ee5a81a5..7d1030d0 100644 --- a/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java +++ b/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; @@ -40,6 +41,7 @@ import org.springframework.data.aerospike.cache.AerospikeCacheKeyProcessor; import org.springframework.data.aerospike.cache.AerospikeCacheKeyProcessorImpl; import org.springframework.data.aerospike.convert.AerospikeCustomConversions; +import org.springframework.data.aerospike.convert.AerospikeCustomConverters; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; import org.springframework.data.aerospike.convert.MappingAerospikeConverter; import org.springframework.data.aerospike.core.AerospikeExceptionTranslator; @@ -59,6 +61,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -109,12 +112,17 @@ public AerospikeTypeAliasAccessor aerospikeTypeAliasAccessor(AerospikeDataSettin : new AerospikeTypeAliasAccessor(); } - @Bean(name = "aerospikeCustomConversions") - public AerospikeCustomConversions customConversions() { - return new AerospikeCustomConversions(customConverters()); + @Bean + public AerospikeCustomConversions customConversions(@Autowired(required = false) + AerospikeCustomConverters converters) { + List aggregatedCustomConverters = new ArrayList<>(customConverters()); + if (converters != null) { + aggregatedCustomConverters.addAll(converters.getCustomConverters()); + } + return new AerospikeCustomConversions(aggregatedCustomConverters); } - protected List customConverters() { + protected List customConverters() { return Collections.emptyList(); } diff --git a/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConversions.java b/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConversions.java index acd9e6f4..9a8e969b 100644 --- a/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConversions.java +++ b/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConversions.java @@ -15,6 +15,7 @@ */ package org.springframework.data.aerospike.convert; +import lombok.Getter; import org.springframework.data.aerospike.mapping.AerospikeSimpleTypes; import org.springframework.data.convert.CustomConversions; @@ -28,15 +29,16 @@ * @author Mark Paluch * @author Christoph Strobl * @author Anastasiia Smirnova - * @see org.springframework.data.convert.CustomConversions + * @see CustomConversions * @see org.springframework.data.mapping.model.SimpleTypeHolder * @see AerospikeSimpleTypes */ public class AerospikeCustomConversions extends CustomConversions { private static final StoreConversions STORE_CONVERSIONS; - private static final List STORE_CONVERTERS; + @Getter + private final List customConverters; static { List converters = new ArrayList<>(); @@ -49,11 +51,12 @@ public class AerospikeCustomConversions extends CustomConversions { } /** - * Create a new instance with a given list of converters. + * Create a new instance with a given list of converters * - * @param converters the list of custom converters. + * @param converters the list of custom converters */ - public AerospikeCustomConversions(final List converters) { + public AerospikeCustomConversions(final List converters) { super(STORE_CONVERSIONS, converters); + this.customConverters = converters; } } diff --git a/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConverters.java b/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConverters.java new file mode 100644 index 00000000..ec052274 --- /dev/null +++ b/src/main/java/org/springframework/data/aerospike/convert/AerospikeCustomConverters.java @@ -0,0 +1,38 @@ +/* + * Copyright 2020 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 + * + * https://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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.aerospike.convert; + +import lombok.Getter; + +import java.util.List; + +/** + * Storage for a list of custom converters + */ +public class AerospikeCustomConverters { + + @Getter + private final List customConverters; + + /** + * Create a storage for custom converters + * + * @param converters a list of custom converters + */ + public AerospikeCustomConverters(final List converters) { + this.customConverters = converters; + } +} diff --git a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java index f922f724..4ee90e62 100644 --- a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java +++ b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeOperations.java @@ -52,7 +52,7 @@ public interface ReactiveAerospikeOperations { MappingContext getMappingContext(); /** - * @return converter in use. + * @return Converter in use. */ MappingAerospikeConverter getAerospikeConverter(); diff --git a/src/test/java/org/springframework/data/aerospike/config/BlockingTestConfig.java b/src/test/java/org/springframework/data/aerospike/config/BlockingTestConfig.java index ac439ed3..3b811a79 100644 --- a/src/test/java/org/springframework/data/aerospike/config/BlockingTestConfig.java +++ b/src/test/java/org/springframework/data/aerospike/config/BlockingTestConfig.java @@ -35,7 +35,7 @@ public class BlockingTestConfig extends AbstractAerospikeDataConfiguration { Environment env; @Override - protected List customConverters() { + protected List customConverters() { return Arrays.asList( SampleClasses.CompositeKey.CompositeKeyToStringConverter.INSTANCE, SampleClasses.CompositeKey.StringToCompositeKeyConverter.INSTANCE diff --git a/src/test/java/org/springframework/data/aerospike/config/ReactiveTestConfig.java b/src/test/java/org/springframework/data/aerospike/config/ReactiveTestConfig.java index b6356552..70fb3a74 100644 --- a/src/test/java/org/springframework/data/aerospike/config/ReactiveTestConfig.java +++ b/src/test/java/org/springframework/data/aerospike/config/ReactiveTestConfig.java @@ -36,7 +36,7 @@ public class ReactiveTestConfig extends AbstractReactiveAerospikeDataConfigurati Environment env; @Override - protected List customConverters() { + protected List customConverters() { return Arrays.asList( SampleClasses.CompositeKey.CompositeKeyToStringConverter.INSTANCE, SampleClasses.CompositeKey.StringToCompositeKeyConverter.INSTANCE diff --git a/src/test/java/org/springframework/data/aerospike/util/QueryUtils.java b/src/test/java/org/springframework/data/aerospike/util/QueryUtils.java index 71100c63..347537b9 100644 --- a/src/test/java/org/springframework/data/aerospike/util/QueryUtils.java +++ b/src/test/java/org/springframework/data/aerospike/util/QueryUtils.java @@ -104,7 +104,8 @@ private static Class checkForPageable(Class argType) { return argType; } - private static MappingAerospikeConverter getMappingAerospikeConverter(AerospikeCustomConversions conversions) { + private static MappingAerospikeConverter getMappingAerospikeConverter(AerospikeCustomConversions conversions) + { MappingAerospikeConverter converter = new MappingAerospikeConverter(new AerospikeMappingContext(), conversions, new AerospikeTypeAliasAccessor(), new AerospikeDataSettings()); converter.afterPropertiesSet();