@Konvert
The annotation @Konvert
is only being processed on abstract functions in interfaces annotated with @Konverter
.
If a @Konvert
-annotated function is a suspend fun
, the generated counterpart is also a suspend fun
.
@Konverter
interface PersonMapper {
@Konvert(mappings=[
Mapping(source="firstName", target="givenName"),
Mapping(source="lastName", target="familyName"),
])
fun toDTO(person: Person): PersonDto
}
class Person(val firstName: String, val lastName: String)
class PersonDto(val givenName: String, val familyName: String)
This will generate
object PersonMapperImpl: PersonMapper {
override fun toDTO(person: Person): PersonDto = PersonDto(
givenName = person.firstName,
familyName = person.lastName
)
}
Parameters
constructor
If your target class has multiple constructors, Konvert tries to automatically determine one constructor (TODO). If you want to enforce a specific constructor, you can use this parameter to define the constructor parameter types here.
priority
So that Konvert can choose a TypeConverter
if multiple match, you can define a custom priority to align with your setup (TODO). The default priority for this annotation is 5000
.
mappings
Define a mapping for each property, which can not be automatically converted. See the @Mapping annotation for details on how to do so.
options
You can define custom options for this annotation processing. See here for available options.