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