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 @@ -463,6 +463,15 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
463
463
return collection .stream ().map (it -> valueConverter .write (it , conversionContext )).collect (Collectors .toList ());
464
464
}
465
465
466
+ if (!documentField .getProperty ().isMap () && sourceValue instanceof Document document ) {
467
+ return new Document (document .entrySet ().stream ().collect (Collectors .toMap (entry -> entry .getKey (), entry -> {
468
+ if (isKeyword (entry .getKey ())) {
469
+ return getMappedValue (documentField , entry .getValue ());
470
+ }
471
+ return entry .getValue ();
472
+ })));
473
+ }
474
+
466
475
return valueConverter .write (value , conversionContext );
467
476
}
468
477
Original file line number Diff line number Diff line change @@ -1528,6 +1528,24 @@ void mappingShouldRetainMapKeyOrder() {
1528
1528
assertThat (target .get ("simpleMap" , Map .class )).containsExactlyEntriesOf (sourceMap );
1529
1529
}
1530
1530
1531
+ @ Test // GH-4510
1532
+ void convertsNestedOperatorValueForPropertyThatHasValueConverter () {
1533
+
1534
+ org .bson .Document mappedObject = mapper .getMappedObject (query (where ("text" ).gt ("spring" ).lt ( "data" )).getQueryObject (),
1535
+ context .getPersistentEntity (WithPropertyValueConverter .class ));
1536
+
1537
+ assertThat (mappedObject ).isEqualTo ("{ 'text' : { $gt : 'gnirps', $lt : 'atad' } }" );
1538
+ }
1539
+
1540
+ @ Test // GH-4510
1541
+ void convertsNestedOperatorValueForPropertyContainingListThatHasValueConverter () {
1542
+
1543
+ org .bson .Document mappedObject = mapper .getMappedObject (query (where ("text" ).gt ("spring" ).in ( "data" )).getQueryObject (),
1544
+ context .getPersistentEntity (WithPropertyValueConverter .class ));
1545
+
1546
+ assertThat (mappedObject ).isEqualTo ("{ 'text' : { $gt : 'gnirps', $in : [ 'atad' ] } }" );
1547
+ }
1548
+
1531
1549
class WithSimpleMap {
1532
1550
Map <String , String > simpleMap ;
1533
1551
}
You can’t perform that action at this time.
0 commit comments