DATAMONGO-2661 - Handle nullable types for KPropertyPath.
Original pull request: #894.
This commit is contained in:
committed by
Mark Paluch
parent
d54ed61581
commit
2a8ffd53d8
@@ -27,7 +27,7 @@ import kotlin.reflect.KProperty1
|
||||
* @since 2.2
|
||||
*/
|
||||
class KPropertyPath<T, U>(
|
||||
internal val parent: KProperty<U>,
|
||||
internal val parent: KProperty<U?>,
|
||||
internal val child: KProperty1<U, T>
|
||||
) : KProperty<T> by child
|
||||
|
||||
@@ -52,7 +52,8 @@ internal fun asString(property: KProperty<*>): String {
|
||||
* Book::author / Author::name isEqualTo "Herman Melville"
|
||||
* ```
|
||||
* @author Tjeu Kayim
|
||||
* @author Yoann de Martino
|
||||
* @since 2.2
|
||||
*/
|
||||
operator fun <T, U> KProperty<T>.div(other: KProperty1<T, U>) =
|
||||
operator fun <T, U> KProperty<T?>.div(other: KProperty1<T, U>) =
|
||||
KPropertyPath(this, other)
|
||||
|
||||
@@ -93,6 +93,15 @@ class KPropertyPathTests {
|
||||
assertThat(property).isEqualTo("entity.book.author.name")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Convert nullable KProperty to field name`() {
|
||||
class Cat(val name: String)
|
||||
class Owner(val cat: Cat?)
|
||||
|
||||
val property = asString(Owner::cat / Cat::name)
|
||||
assertThat(property).isEqualTo("cat.name")
|
||||
}
|
||||
|
||||
class Book(val title: String, val author: Author)
|
||||
class Author(val name: String)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user