diff --git a/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java b/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java
index 5441dae5..ab2ea1bd 100644
--- a/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java
@@ -26,7 +26,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.data.annotation.Persistent;
-import org.springframework.data.couchbase.core.convert.CustomConversions;
+import org.springframework.data.convert.CustomConversions;
+import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService;
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
@@ -49,6 +50,7 @@ import org.springframework.util.StringUtils;
*
* @author Simon Baslé
* @author Subhashni Balakrishnan
+ * @author Mark Paluch
*/
public class CouchbaseConfigurationSupport {
/**
@@ -130,7 +132,7 @@ public class CouchbaseConfigurationSupport {
*/
@Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
public CustomConversions customConversions() {
- return new CustomConversions(Collections.emptyList());
+ return new CouchbaseCustomConversions(Collections.emptyList());
}
/**
diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java
index 38ae47df..b242ac88 100644
--- a/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java
+++ b/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2015 the original author or authors
+ * Copyright 2012-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +20,15 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.EntityInstantiators;
+import org.springframework.data.convert.CustomConversions;
+
+import java.util.Collections;
/**
* An abstract {@link CouchbaseConverter} that provides the basics for the {@link MappingCouchbaseConverter}.
*
* @author Michael Nitschinger
+ * @author Mark Paluch
*/
public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, InitializingBean {
@@ -41,7 +45,7 @@ public abstract class AbstractCouchbaseConverter implements CouchbaseConverter,
/**
* Holds the custom conversions.
*/
- protected CustomConversions conversions = new CustomConversions();
+ protected CustomConversions conversions = new CouchbaseCustomConversions(Collections.emptyList());
/**
* Create a new converter and hand it over the {@link ConversionService}
@@ -94,16 +98,13 @@ public abstract class AbstractCouchbaseConverter implements CouchbaseConverter,
return null;
}
- Class> targetType = this.conversions.getCustomWriteTarget(value.getClass());
- if (targetType != null) {
- return this.conversionService.convert(value, targetType);
- }
- return value;
+ return this.conversions.getCustomWriteTarget(value.getClass()) //
+ .map(it -> (Object) this.conversionService.convert(value, it)) //
+ .orElse(value);
}
@Override
public Class> getWriteClassFor(Class> clazz) {
- Class> targetType = this.conversions.getCustomWriteTarget(clazz);
- return targetType != null ? targetType : clazz;
+ return this.conversions.getCustomWriteTarget(clazz).orElse(clazz);
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java b/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java
new file mode 100644
index 00000000..269b1ea5
--- /dev/null
+++ b/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.couchbase.core.convert;
+
+import org.springframework.data.mapping.model.SimpleTypeHolder;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Value object to capture custom conversion.
+ *
+ * Types that can be mapped directly onto JSON are considered simple ones, because they neither need deeper
+ * inspection nor nested conversion.
+ *
+ * @author Michael Nitschinger
+ * @author Oliver Gierke
+ * @author Mark Paluch
+ * @author Subhashni Balakrishnan
+ * @see org.springframework.data.convert.CustomConversions
+ * @see SimpleTypeHolder
+ * @since 2.0
+ */
+public class CouchbaseCustomConversions extends org.springframework.data.convert.CustomConversions {
+
+ private static final StoreConversions STORE_CONVERSIONS;
+
+ private static final List