@KonvertTo
The annotation @KonvertTo
can be applied to classes and will generate an extension function to that class to convert it to the defined target class.
@KonvertTo(PersonDto::class)
class Person(val name: String, val age: Int)
class PersonDto(val name: String, val age: Int)
This will generate
fun Person.toPersonDto() = PersonDto(name = name, age = age)
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 3000
.
mappings
Define a mapping for each property, which can not be automatically converted. See the @Mapping annotation for details on how to do so.
mapFunctionName
This parameter can be used to change the default name of the extension function (which is to${value.simpleName}
, e.g. toPerson
) to whatever you specify. Some typical use-cases for changing the default: the name gets too long or is already taken.
options
You can define custom options for this annotation processing. See here for available options.