Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/kotlin/org/springframework/data/core/KPropertyPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.springframework.data.core

import org.springframework.data.mapping.KIterablePropertyPath as MappingKIterablePropertyPath
import org.springframework.data.mapping.KPropertyPath as MappingKPropertyPath
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty1

Expand Down Expand Up @@ -101,6 +103,7 @@ internal class KIterablePropertyReference<T, M, out P>(
*
* @author Tjeu Kayim
* @author Mikhail Polivakha
* @author hutiefang
* @since 4.1
*/
internal fun asString(property: KProperty<*>): String {
Expand All @@ -109,8 +112,13 @@ internal fun asString(property: KProperty<*>): String {
is KPropertyPath<*, *> ->
"${asString(property.property)}.${property.leaf.name}"

is MappingKPropertyPath<*, *> ->
"${asString(property.parent)}.${property.child.name}"

is MappingKIterablePropertyPath<*, *> ->
"${asString(property.parent)}.${property.child.name}"

else -> property.name
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import kotlin.reflect.KProperty1
* @author Tjeu Kayim
* @author Mark Paluch
* @author Yoann de Martino
* @author hutiefang
* @since 2.5
*/
private class KPropertyPath<T, U>(
internal class KPropertyPath<T, U>(
val parent: KProperty<U?>,
val child: KProperty1<U, T>
) : KProperty<T> by child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package org.springframework.data.mapping

import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.springframework.data.core.toDotPath as coreToDotPath

/**
* Unit tests for [KPropertyPath] and its extensions.
Expand All @@ -25,6 +26,7 @@ import org.junit.Test
* @author Yoann de Martino
* @author Mark Paluch
* @author Mikhail Polivakha
* @author hutiefang
*/
class KPropertyPathTests {

Expand All @@ -44,6 +46,14 @@ class KPropertyPathTests {
assertThat(property).isEqualTo("author.name")
}

@Test // GH-3503
fun `Core toDotPath renders nested mapping KProperty`() {

val property = (Book::author / Author::name).coreToDotPath()

assertThat(property).isEqualTo("author.name")
}

@Test // GH-3010
fun `Convert from Iterable nested KProperty to field name`() {

Expand All @@ -52,6 +62,22 @@ class KPropertyPathTests {
assertThat(property).isEqualTo("books.title")
}

@Test // GH-3503
fun `Core toDotPath renders iterable mapping KProperty`() {

val property = (Author::books / Book::title).coreToDotPath()

assertThat(property).isEqualTo("books.title")
}

@Test // GH-3503
fun `Core toDotPath renders recursively nested mapping KProperty`() {

val property = (Author::books / Book::author / Author::name).coreToDotPath()

assertThat(property).isEqualTo("books.author.name")
}

@Test // GH-3010
fun `Convert from Iterable nested Iterable Property to field name`() {

Expand Down
Loading