Fix regression in value to String mapping.
Previous versions allow arbitrary values to be mapped to an string property by calling the ObjectToString converter. This behaviour got lost and is not reestablished. Closes #4371 Original pull request #4373
This commit is contained in:
committed by
Mark Paluch
parent
fb43e85ea5
commit
b9af92059d
@@ -2329,8 +2329,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
if (source instanceof Collection) {
|
||||
|
||||
Class<?> rawType = typeHint.getType();
|
||||
if (!Object.class.equals(rawType)) {
|
||||
if (!Object.class.equals(rawType) && !String.class.equals(rawType)) {
|
||||
|
||||
if (!rawType.isArray() && !ClassUtils.isAssignable(Iterable.class, rawType)) {
|
||||
|
||||
throw new MappingException(
|
||||
String.format(INCOMPATIBLE_TYPES, source, source.getClass(), rawType, getPath()));
|
||||
}
|
||||
@@ -2359,11 +2361,6 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return (S) dbRefConverter.convert(context, (DBRef) source, typeHint);
|
||||
}
|
||||
|
||||
if (source instanceof Collection) {
|
||||
throw new MappingException(
|
||||
String.format(INCOMPATIBLE_TYPES, source, BasicDBList.class, typeHint.getType(), getPath()));
|
||||
}
|
||||
|
||||
if (BsonUtils.supportsBson(source)) {
|
||||
return (S) documentConverter.convert(context, BsonUtils.asBson(source), typeHint);
|
||||
}
|
||||
|
||||
@@ -2858,6 +2858,14 @@ class MappingMongoConverterUnitTests {
|
||||
assertThat(converter.read(Cyclic.class, source).cycle.value).isEqualTo("v2");
|
||||
}
|
||||
|
||||
@Test // GH-4371
|
||||
void shouldConvertTypesToStringTargetType() {
|
||||
|
||||
org.bson.Document source = org.bson.Document.parse("{\n" + " city : [\"Gotham\", \"Metropolis\"]\n" + "}\n");
|
||||
|
||||
assertThat(converter.read(Address.class, source).city).isEqualTo("Gotham,Metropolis");
|
||||
}
|
||||
|
||||
static class GenericType<T> {
|
||||
T content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user