spring-projects / spring-projects/spring-data-mongodb

Remove deprecations for methods taking KClass? [DATAMONGO-2395]

Open
#3,228 1 comment 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Dec 30, 2020.

in: kotlin type: enhancement
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Johan Haleby opened DATAMONGO-2395 and commented

Hi, 

 

In Spring Data MongoDB 2.1.x I have code that looks like this:

 

 

fun createCollectionsIfNotExists(vararg entityClasses: KClass<*>) = entityClasses.forEach { entityClass ->
 if (!mongo.collectionExists(entityClass)) {
 mongo.createCollection(entityClass)
 }
}
createCollectionsIfNotExists(MongoDTO1::class, MongoDTO2::class, MongoDTO3::class, MongoDTO4::class)

 

 

In 2.2 "collectionExists" and "createCollection" has been deprecated in favor of reified counterparts.  However invoking the reified methods is difficult if you just have "KClass"  (see https://stackoverflow.com/questions/55399737/calling-a-fun-with-reified-type-parameter-if-you-just-have-a-kclass-object). Is there a recommended approach to deal with situations like the one I have in 2.2 or could both method variants be retained (i.e. both KClass and the reified version)?


Affects: 2.2 GA (Moore)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.