@Konverter
@KComponent
interface EntityConverter {
fun convertToEntity(dto: DTO): Entity
fun convertToEntityWithList(dto: DTO): Entity = convertToEntity(dto).apply {
fillCollections(dto)
}
private fun Entity.fillCollections(dto: DTO) {
list.addAll(dto.list)
set.addAll(dto.set)
}
}
data class DTO(
val a: String,
val b: String,
val list: List<String>,
val set: Set<String>,
)
class Entity(
val a: String,
val b: String,
) {
val list: MutableList<String> = mutableListOf()
val set: MutableSet<String> = mutableSetOf()
}
leads to an error: 'fillCollections' overrides nothing
The result implementation of the Konverter looks like this:
@Component
public object EntityConverterImpl : EntityConverter {
@GeneratedKonverter(priority = 5_000)
override fun convertToEntity(dto: DTO): Entity = Entity(
a = dto.a,
b = dto.b
)
@GeneratedKonverter(priority = 2_000)
override fun convertToEntityWithList(dto: DTO): Entity = super.convertToEntityWithList(dto)
@GeneratedKonverter(priority = 2_000)
override fun fillCollections(dto: DTO): Unit = super.fillCollections(dto) // <-- here are problems
}
Problem 1: it should not override private functions
Problem 2: even if the function isn't private, it still should not try to override a member extension function or it should use a proper workaround somehow, please see https://youtrack.jetbrains.com/issue/KT-11488
Having the following code
leads to an error:
'fillCollections' overrides nothing
The result implementation of the Konverter looks like this:
Problem 1: it should not override
private
functions Problem 2: even if the function isn'tprivate
, it still should not try to override a member extension function or it should use a proper workaround somehow, please see https://youtrack.jetbrains.com/issue/KT-11488