Fix NPE when rendering untyped aggregation operation as part of criteria query.
Resolves: #4687 Original pull request: #4695
This commit is contained in:
committed by
Mark Paluch
parent
0b4ca78084
commit
c7800a6549
@@ -588,8 +588,11 @@ public class QueryMapper {
|
||||
}
|
||||
|
||||
if (source instanceof AggregationExpression age) {
|
||||
return age
|
||||
.toDocument(new RelaxedTypeBasedAggregationOperationContext(entity.getType(), this.mappingContext, this));
|
||||
|
||||
if(entity == null) {
|
||||
return age.toDocument();
|
||||
}
|
||||
return age.toDocument(new RelaxedTypeBasedAggregationOperationContext(entity.getType(), this.mappingContext, this));
|
||||
}
|
||||
|
||||
if (source instanceof MongoExpression exr) {
|
||||
|
||||
@@ -1529,6 +1529,15 @@ public class QueryMapperUnitTests {
|
||||
assertThat(mappedObject).isEqualTo("{ $expr : { $expr : { $gt : [ '$foo', '$budget'] } } }");
|
||||
}
|
||||
|
||||
@Test // GH-4687
|
||||
void usageOfUntypedAggregationShouldRenderOperationsAsIs() {
|
||||
|
||||
Query query = query(expr(Expr.valueOf(ComparisonOperators.valueOf("field").greaterThan("budget"))));
|
||||
org.bson.Document mappedObject = mapper.getMappedObject(query.getQueryObject(),
|
||||
context.getPersistentEntity(Object.class));
|
||||
assertThat(mappedObject).isEqualTo("{ $expr : { $expr : { $gt : [ '$field', '$budget'] } } }");
|
||||
}
|
||||
|
||||
@Test // GH-2750
|
||||
void usesMongoExpressionDocumentAsIsIfItIsNotAnAggregationExpression() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user