diff --git a/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensions.kt b/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensions.kt index 6653cd67a..e79aa5520 100644 --- a/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensions.kt +++ b/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensions.kt @@ -220,9 +220,24 @@ inline fun MongoOperations.group(criteria: Criteria, inputColl * @author Sebastien Deleuze * @since 2.0 */ -@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("aggregate(aggregation)")) -inline fun MongoOperations.aggregate(aggregation: Aggregation, inputType: KClass<*>): AggregationResults = - aggregate(aggregation, inputType.java, O::class.java) +@Deprecated( + "Since 2.2, use the reified variant", + replaceWith = ReplaceWith("aggregate(aggregation)") +) +inline fun MongoOperations.aggregate( + aggregation: Aggregation, + inputType: KClass<*> +): AggregationResults = + aggregate(aggregation, inputType.java, O::class.java) + +/** + * Extension for [MongoOperations.aggregate] leveraging reified type parameters. + * + * @author Mark Paluch + * @since 3.2 + */ +inline fun MongoOperations.aggregate(aggregation: Aggregation): AggregationResults = + aggregate(aggregation, I::class.java, O::class.java) /** * Extension for [MongoOperations.aggregate] leveraging reified type parameters. @@ -230,8 +245,11 @@ inline fun MongoOperations.aggregate(aggregation: Aggregation, * @author Sebastien Deleuze * @since 2.0 */ -inline fun MongoOperations.aggregate(aggregation: Aggregation, collectionName: String): AggregationResults = - aggregate(aggregation, collectionName, O::class.java) +inline fun MongoOperations.aggregate( + aggregation: Aggregation, + collectionName: String +): AggregationResults = + aggregate(aggregation, collectionName, O::class.java) /** * Extension for [MongoOperations.aggregateStream] leveraging reified type parameters. @@ -239,9 +257,24 @@ inline fun MongoOperations.aggregate(aggregation: Aggregation, * @author Sebastien Deleuze * @since 2.0 */ -@Deprecated("Since 2.2, use the reified variant", replaceWith = ReplaceWith("aggregateStream(aggregation)")) -inline fun MongoOperations.aggregateStream(aggregation: Aggregation, inputType: KClass<*>): CloseableIterator = - aggregateStream(aggregation, inputType.java, O::class.java) +@Deprecated( + "Since 2.2, use the reified variant", + replaceWith = ReplaceWith("aggregateStream(aggregation)") +) +inline fun MongoOperations.aggregateStream( + aggregation: Aggregation, + inputType: KClass<*> +): CloseableIterator = + aggregateStream(aggregation, inputType.java, O::class.java) + +/** + * Extension for [MongoOperations.aggregateStream] leveraging reified type parameters. + * + * @author Mark Paluch + * @since 3.2 + */ +inline fun MongoOperations.aggregateStream(aggregation: Aggregation): CloseableIterator = + aggregateStream(aggregation, I::class.java, O::class.java) /** * Extension for [MongoOperations.aggregateStream] leveraging reified type parameters. @@ -249,8 +282,11 @@ inline fun MongoOperations.aggregateStream(aggregation: Aggreg * @author Sebastien Deleuze * @since 2.0 */ -inline fun MongoOperations.aggregateStream(aggregation: Aggregation, collectionName: String): CloseableIterator = - aggregateStream(aggregation, collectionName, O::class.java) +inline fun MongoOperations.aggregateStream( + aggregation: Aggregation, + collectionName: String +): CloseableIterator = + aggregateStream(aggregation, collectionName, O::class.java) /** * Extension for [MongoOperations.mapReduce] leveraging reified type parameters. diff --git a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensionsTests.kt b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensionsTests.kt index 6181b3607..7e8eb71c2 100644 --- a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensionsTests.kt +++ b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/MongoOperationsExtensionsTests.kt @@ -241,7 +241,28 @@ class MongoOperationsExtensionsTests { val aggregation = mockk() operations.aggregate(aggregation, Second::class) - verify { operations.aggregate(aggregation, Second::class.java, First::class.java) } + verify { + operations.aggregate( + aggregation, + Second::class.java, + First::class.java + ) + } + } + + @Test // #3508 + fun `aggregate(Aggregation) with reified type parameter extension should call its Java counterpart`() { + + val aggregation = mockk() + + operations.aggregate(aggregation) + verify { + operations.aggregate( + aggregation, + Second::class.java, + First::class.java + ) + } } @Test // DATAMONGO-1689 @@ -261,7 +282,28 @@ class MongoOperationsExtensionsTests { val aggregation = mockk() operations.aggregateStream(aggregation, Second::class) - verify { operations.aggregateStream(aggregation, Second::class.java, First::class.java) } + verify { + operations.aggregateStream( + aggregation, + Second::class.java, + First::class.java + ) + } + } + + @Test // #3508 + fun `aggregateStream(Aggregation) with reified type parameter extension should call its Java counterpart`() { + + val aggregation = mockk() + + operations.aggregateStream(aggregation) + verify { + operations.aggregateStream( + aggregation, + Second::class.java, + First::class.java + ) + } } @Test // DATAMONGO-1689 @@ -271,7 +313,13 @@ class MongoOperationsExtensionsTests { val collectionName = "foo" operations.aggregateStream(aggregation, collectionName) - verify { operations.aggregateStream(aggregation, collectionName, First::class.java) } + verify { + operations.aggregateStream( + aggregation, + collectionName, + First::class.java + ) + } } @Test // DATAMONGO-1689