Propagated CouchbaseCustomConverters bean into MappingConverter (#1885)

* Propagated CouchbaseCustomConverters bean into MappingConverter.

Just a polishing fix to propagate CouchbaseCustomConversions directly to MappingCouchbaseConverter -> AbstractCouchbaseConverter , So that we won't have to set it explicitly.

* Removed unnecessary constructor.
This commit is contained in:
Vipul Gupta
2024-01-11 05:04:44 +05:30
committed by GitHub
parent 359ade2e7b
commit 6e175722aa
7 changed files with 51 additions and 21 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.couchbase.domain;
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
@@ -37,8 +38,9 @@ public class AbstractingMappingCouchbaseConverter extends MappingCouchbaseConver
*/
public AbstractingMappingCouchbaseConverter(
final MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext,
final String typeKey) {
super(mappingContext, typeKey);
final String typeKey,
final CouchbaseCustomConversions couchbaseCustomConversions) {
super(mappingContext, typeKey, couchbaseCustomConversions);
this.typeMapper = new AbstractingTypeMapper(typeKey);
}

View File

@@ -211,8 +211,7 @@ public class Config extends AbstractCouchbaseConfiguration {
// that has an getAliasFor(info) that just returns getType().getName().
// Our CustomMappingCouchbaseConverter uses a TypeBasedCouchbaseTypeMapper that will
// use the DocumentType annotation
MappingCouchbaseConverter converter = new CustomMappingCouchbaseConverter(couchbaseMappingContext, typeKey());
converter.setCustomConversions(couchbaseCustomConversions);
MappingCouchbaseConverter converter = new CustomMappingCouchbaseConverter(couchbaseMappingContext, typeKey(), couchbaseCustomConversions);
return converter;
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.couchbase.domain;
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
@@ -37,4 +38,21 @@ public class CustomMappingCouchbaseConverter extends MappingCouchbaseConverter {
this.typeMapper = new TypeBasedCouchbaseTypeMapper(typeKey);
}
/**
* this constructer creates a TypeBasedCouchbaseTypeMapper with the specified couchbaseCustomConversions and typeKey
* while MappingCouchbaseConverter uses a DefaultCouchbaseTypeMapper typeMapper = new DefaultCouchbaseTypeMapper(typeKey != null ? typeKey :
* TYPEKEY_DEFAULT);
*
* @param mappingContext
* @param typeKey - the typeKey to be used (normally "_class")
* @param couchbaseCustomConversions - custom conversions to use
*/
public CustomMappingCouchbaseConverter(
final MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext,
final String typeKey,
final CouchbaseCustomConversions couchbaseCustomConversions) {
super(mappingContext, typeKey, couchbaseCustomConversions);
this.typeMapper = new TypeBasedCouchbaseTypeMapper(typeKey);
}
}

View File

@@ -124,8 +124,8 @@ public class CouchbaseAbstractRepositoryIntegrationTests extends ClusterAwareInt
// Our CustomMappingCouchbaseConverter uses a TypeBasedCouchbaseTypeMapper that will
// use the DocumentType annotation
MappingCouchbaseConverter converter = new AbstractingMappingCouchbaseConverter(couchbaseMappingContext,
typeKey());
converter.setCustomConversions(couchbaseCustomConversions);
typeKey(),
couchbaseCustomConversions);
return converter;
}