DATADOC-75 - Rename setConverters(...) to addConverters(...) in MongoConverter implementations
This commit is contained in:
@@ -27,6 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mongodb.BasicDBList;
|
||||
import com.mongodb.BasicDBObject;
|
||||
@@ -46,6 +47,7 @@ import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
@@ -86,24 +88,27 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
||||
protected String defaultDatabase;
|
||||
|
||||
public MappingMongoConverter() {
|
||||
initializeConverters();
|
||||
|
||||
}
|
||||
|
||||
public MappingMongoConverter(MappingContext mappingContext) {
|
||||
this.mappingContext = mappingContext;
|
||||
initializeConverters();
|
||||
}
|
||||
|
||||
public MappingMongoConverter(MappingContext mappingContext, List<Converter<?, ?>> converters) {
|
||||
this.mappingContext = mappingContext;
|
||||
if (null != converters) {
|
||||
for (Converter<?, ?> c : converters) {
|
||||
registerConverter(c);
|
||||
conversionService.addConverter(c);
|
||||
}
|
||||
}
|
||||
initializeConverters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom {@link Converter} or {@link ConverterFactory} instances to be used that will take presidence over
|
||||
* metadata driven conversion between of objects to/from DBObject
|
||||
*
|
||||
* @param converters
|
||||
*/
|
||||
public void addConverters(List<Converter<?, ?>> converters) {
|
||||
if (null != converters) {
|
||||
for (Converter<?, ?> c : converters) {
|
||||
registerConverter(c);
|
||||
conversionService.addConverter(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspects the given {@link Converter} for the types it can convert and registers the pair for custom type conversion
|
||||
@@ -596,7 +601,8 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
||||
}
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
initializeConverters();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -129,11 +129,12 @@ public class SimpleMongoConverter implements MongoConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets custom {@link Converter} or {@link ConverterFactory} instances to be used.
|
||||
* Add custom {@link Converter} or {@link ConverterFactory} instances to be used that will take presidence over
|
||||
* using object traversal to convert and object to/from DBObject
|
||||
*
|
||||
* @param converters
|
||||
*/
|
||||
public void setConverters(Set<?> converters) {
|
||||
public void addConverters(Set<?> converters) {
|
||||
for (Object converter : converters) {
|
||||
boolean added = false;
|
||||
if (converter instanceof Converter) {
|
||||
|
||||
@@ -326,7 +326,7 @@ public class SimpleMongoConverterTests {
|
||||
converters.add(new LocalDateToDateConverter());
|
||||
converters.add(new DateToLocalDateConverter());
|
||||
|
||||
converter.setConverters(converters);
|
||||
converter.addConverters(converters);
|
||||
|
||||
AnotherPerson person = new AnotherPerson();
|
||||
person.birthDate = new LocalDate();
|
||||
|
||||
@@ -76,7 +76,9 @@ public class MappingMongoConverterUnitTests {
|
||||
customSimpleTypes.add(LocalDate.class);
|
||||
mappingContext.setCustomSimpleTypes(customSimpleTypes);
|
||||
|
||||
converter = new MappingMongoConverter(mappingContext, converters);
|
||||
converter = new MappingMongoConverter(mappingContext);
|
||||
converter.addConverters(converters);
|
||||
converter.afterPropertiesSet();
|
||||
|
||||
Person person = new Person();
|
||||
person.birthDate = new LocalDate();
|
||||
|
||||
Reference in New Issue
Block a user