File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
main/java/org/springframework/data/mongodb/core/convert
test/java/org/springframework/data/mongodb/core/convert Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -455,6 +455,15 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
455
455
return collection .stream ().map (it -> valueConverter .write (it , conversionContext )).collect (Collectors .toList ());
456
456
}
457
457
458
+ if (!documentField .getProperty ().isMap () && sourceValue instanceof Document document ) {
459
+ return new Document (document .entrySet ().stream ().collect (Collectors .toMap (entry -> entry .getKey (), entry -> {
460
+ if (isKeyword (entry .getKey ())) {
461
+ return getMappedValue (documentField , entry .getValue ());
462
+ }
463
+ return entry .getValue ();
464
+ })));
465
+ }
466
+
458
467
return valueConverter .write (value , conversionContext );
459
468
}
460
469
Original file line number Diff line number Diff line change @@ -1509,6 +1509,24 @@ void convertsListOfValuesForPropertyThatHasValueConverterButIsNotCollectionLikeO
1509
1509
assertThat (mappedObject ).isEqualTo ("{ 'text' : { $in : ['gnirps', 'atad'] } }" );
1510
1510
}
1511
1511
1512
+ @ Test // GH-4510
1513
+ void convertsNestedOperatorValueForPropertyThatHasValueConverter () {
1514
+
1515
+ org .bson .Document mappedObject = mapper .getMappedObject (query (where ("text" ).gt ("spring" ).lt ( "data" )).getQueryObject (),
1516
+ context .getPersistentEntity (WithPropertyValueConverter .class ));
1517
+
1518
+ assertThat (mappedObject ).isEqualTo ("{ 'text' : { $gt : 'gnirps', $lt : 'atad' } }" );
1519
+ }
1520
+
1521
+ @ Test // GH-4510
1522
+ void convertsNestedOperatorValueForPropertyContainingListThatHasValueConverter () {
1523
+
1524
+ org .bson .Document mappedObject = mapper .getMappedObject (query (where ("text" ).gt ("spring" ).in ( "data" )).getQueryObject (),
1525
+ context .getPersistentEntity (WithPropertyValueConverter .class ));
1526
+
1527
+ assertThat (mappedObject ).isEqualTo ("{ 'text' : { $gt : 'gnirps', $in : [ 'atad' ] } }" );
1528
+ }
1529
+
1512
1530
class WithDeepArrayNesting {
1513
1531
1514
1532
List <WithNestedArray > level0 ;
You can’t perform that action at this time.
0 commit comments