kschlesselmann
11/22/2018, 7:08 AMimport org.springframework.boot.ApplicationRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.data.annotation.Transient
import org.springframework.data.mongodb.core.mapping.Field
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Flux
import java.util.*
class Test(
list: List<String>,
val id: UUID = UUID.randomUUID()
) {
@Field("list")
private val _mutableList: MutableList<String> = list.toMutableList()
val list: List<String>
@Transient get() = _mutableList
}
@Repository
interface TestRepository : ReactiveCrudRepository<Test, UUID>
@SpringBootApplication
class DemoMongoMappingApplication {
@Bean
fun runner(testRepository: TestRepository) = ApplicationRunner {_ ->
Flux.just("a", "b", "c")
.map { Test(listOf(it)) }
.collectList()
.flatMapMany { testRepository.saveAll(it) }
.flatMap { testRepository.findById(it.id) }
.subscribe { println("Found $it.id") }
}
}
fun main(args: Array<String>) {
runApplication<DemoMongoMappingApplication>(*args)
}
Sadly this fails during load of my entities with org.springframework.data.mapping.MappingException: No property list found on entity class com.example.demomongomapping.Test to bind constructor parameter to!
. The problem seems to be with the backing property _list
. Any suggestions how you solve those issues?karelpeeters
11/22/2018, 7:12 AM@JvmField
can help?kschlesselmann
11/22/2018, 7:14 AMkschlesselmann
11/22/2018, 7:22 AMclass Test(
list: List<String>,
val id: UUID = UUID.randomUUID()
) {
val list: List<String> = list.toMutableList()
fun doSomethingMutable() {
list as MutableList
list.add("foo")
}
}
would solve the issue as well … what do you guys think of that?karelpeeters
11/22/2018, 7:23 AMkschlesselmann
11/22/2018, 7:27 AMaarjav
11/22/2018, 8:14 AMkschlesselmann
11/22/2018, 9:15 AMvar
. I don't want to compromise my domain model for mongo technical details