Skip to content

Commit

Permalink
Fix property value conversion in query mapper for nested values.
Browse files Browse the repository at this point in the history
  • Loading branch information
christophstrobl committed Sep 28, 2023
1 parent 6ae7cda commit 02f5819
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,15 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
return collection.stream().map(it -> valueConverter.write(it, conversionContext)).collect(Collectors.toList());
}

if(!documentField.getProperty().isMap() && sourceValue instanceof Document document) {
return new Document(document.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> {
if(isKeyword(entry.getKey())) {
return getMappedValue(documentField, entry.getValue());
}
return entry.getValue();
})));
}

return valueConverter.write(value, conversionContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,24 @@ void convertsListOfValuesForPropertyThatHasValueConverterButIsNotCollectionLikeO
assertThat(mappedObject).isEqualTo("{ 'text' : { $in : ['gnirps', 'atad'] } }");
}

@Test // GH-4510
void convertsNestedOperatorValueForPropertyThatHasValueConverter() {

org.bson.Document mappedObject = mapper.getMappedObject(query(where("text").gt("spring").lt( "data")).getQueryObject(),
context.getPersistentEntity(WithPropertyValueConverter.class));

assertThat(mappedObject).isEqualTo("{ 'text' : { $gt : 'gnirps', $lt : 'atad' } }");
}

@Test // GH-4510
void convertsNestedOperatorValueForPropertyContainingListThatHasValueConverter() {

org.bson.Document mappedObject = mapper.getMappedObject(query(where("text").gt("spring").in( "data")).getQueryObject(),
context.getPersistentEntity(WithPropertyValueConverter.class));

assertThat(mappedObject).isEqualTo("{ 'text' : { $gt : 'gnirps', $in : [ 'atad' ] } }");
}

class WithDeepArrayNesting {

List<WithNestedArray> level0;
Expand Down

0 comments on commit 02f5819

Please sign in to comment.