|
27 | 27 | import org.bson.Document; |
28 | 28 | import org.bson.conversions.Bson; |
29 | 29 | import org.bson.types.ObjectId; |
30 | | - |
31 | 30 | import org.springframework.core.convert.ConversionService; |
32 | 31 | import org.springframework.core.convert.converter.Converter; |
33 | 32 | import org.springframework.data.annotation.Reference; |
| 33 | +import org.springframework.data.convert.PropertyValueConverter; |
| 34 | +import org.springframework.data.convert.ValueConversionContext; |
34 | 35 | import org.springframework.data.domain.Example; |
35 | 36 | import org.springframework.data.mapping.Association; |
36 | 37 | import org.springframework.data.mapping.MappingException; |
@@ -438,9 +439,18 @@ protected Object getMappedValue(Field documentField, Object sourceValue) { |
438 | 439 |
|
439 | 440 | if (documentField.getProperty() != null |
440 | 441 | && converter.getCustomConversions().getPropertyValueConversions().hasValueConverter(documentField.getProperty())) { |
441 | | - return converter.getCustomConversions().getPropertyValueConversions() |
442 | | - .getValueConverter(documentField.getProperty()) |
443 | | - .write(value, new MongoConversionContext(documentField.getProperty(), converter)); |
| 442 | + |
| 443 | + MongoConversionContext conversionContext = new MongoConversionContext(documentField.getProperty(), converter); |
| 444 | + PropertyValueConverter<Object, Object, ValueConversionContext<MongoPersistentProperty>> valueConverter = converter |
| 445 | + .getCustomConversions().getPropertyValueConversions().getValueConverter(documentField.getProperty()); |
| 446 | + |
| 447 | + /* might be an $in clause with multiple entries */ |
| 448 | + if (!documentField.getProperty().isCollectionLike() && sourceValue instanceof Collection<?>) { |
| 449 | + Collection<?> collection = (Collection<?>) sourceValue; |
| 450 | + return collection.stream().map(it -> valueConverter.write(it, conversionContext)).collect(Collectors.toList()); |
| 451 | + } |
| 452 | + |
| 453 | + return valueConverter.write(value, conversionContext); |
444 | 454 | } |
445 | 455 |
|
446 | 456 | if (documentField.isIdField() && !documentField.isAssociation()) { |
|
0 commit comments