DATADOC-268 - CustomConversion considers types only simple for registered write converters.
In cases where only a reading converter is registered (e.g. to manually instantiate the object instance) the type the reading converter is registered for must not be regarded as simple as it will be written to the DBObject as is.
This commit is contained in:
@@ -104,8 +104,10 @@ public class CustomConversions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given type is considered to be simple.
|
||||
* Returns whether the given type is considered to be simple. That means it's either a general simple type or we have
|
||||
* a writing {@link Converter} registered for a particular type.
|
||||
*
|
||||
* @see SimpleTypeHolder#isSimpleType(Class)
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@@ -176,7 +178,6 @@ public class CustomConversions {
|
||||
|
||||
if (isMongoBasicType(pair.getSourceType())) {
|
||||
readingPairs.add(pair);
|
||||
customSimpleTypes.add(pair.getTargetType());
|
||||
}
|
||||
|
||||
if (isMongoBasicType(pair.getTargetType())) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CustomConversionsUnitTests {
|
||||
@Test
|
||||
public void considersTypesWeRegisteredConvertersForAsSimple() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions( Arrays.asList(UuidToStringConverter.INSTANCE));
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(UuidToStringConverter.INSTANCE));
|
||||
assertThat(conversions.isSimpleType(UUID.class), is(true));
|
||||
}
|
||||
|
||||
@@ -105,6 +105,15 @@ public class CustomConversionsUnitTests {
|
||||
assertThat(conversionService.canConvert(String.class, UUID.class), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATADOC-259
|
||||
*/
|
||||
@Test
|
||||
public void doesNotConsiderTypeSimpleIfOnlyReadConverterIsRegistered() {
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(StringToUUIDConverter.INSTANCE));
|
||||
assertThat(conversions.isSimpleType(UUID.class), is(false));
|
||||
}
|
||||
|
||||
enum UuidToStringConverter implements Converter<UUID, String> {
|
||||
INSTANCE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user