This commit does not belong to lớn any branch on this repository, & may belong lớn a fork outside of the repository.


Bạn đang xem: What is the meaning of "kewt"?

Kewt - Kotlin đáng yêu data-class mapping tool Quick start Mapping strategies General concepts Implicitly by type, if it is not ambiguous Example Type match Negative example (ambiguous mapping): Type match using a converter function Implicitly by name, if it is not ambiguous Example Explicitly in
Mapping annotation Example Explicit mapping Explicit converter Examples Field lifting bản đồ collection elements Protobuf Dependencies Configuration Spring Debugging Logging White/black listing packages
*
*
*

Kewt - Kotlin dễ thương data-class mapping toolinspired by Mapstruct

Quick start

build.gradle.kts:


plugins kotlin("kapt") version "1.3.72" //kotlinVersionrepositories jcenter()dependencies implementation("com.romanhords.com.mfarsikov:kewt-annotations:0.7.0") kapt("com.romanhords.com.mfarsikov:kewt-map-processor:0.7.0")

data class Person(val id: UUID, val name: String, val age: Int)data class Employee(val id: UUID, val name: String, val age: Int)
Generatedclass PersonMapperImpl : PersonMapper override fun toEmployee(person: Person) = Employee( age = person.age, id = person.id, name = person.name )

Mapping strategies

General concepts

Classes can be mapped if each target field have found a single source.Mapping cannot be done if any target property can be mapped from more than one source.In the same time it is allowed to lớn have not mapped (extra) sources.

Implicitly by type, if it is not ambiguous

Type matched if:

Types are identical:String => StringEmployee => EmployeeList => ListExist conversion function (abstract or not):String => Int if (String) -> Int conversion function providedPerson => Employee if (Person) -> Employee conversion function providedList => list if (String) -> Int conversion function providedList => list if (Person) -> Employee conversion function provided

ExampleType match
data class Person (val personId: UUID, val personName: String, val personAge: Int )data class Employee(val employeeId: UUID, val employeeName: String, val employeeAge: Int)


Xem thêm: Con Bò Sữa Tiếng Anh Là Gì : Định Nghĩa, Ví Dụ Anh Việt, Bé Tập Nói Tiếng Anh

Generatedclass PersonMapperImpl : PersonMapper override fun toEmployee(person: Person) = Employee( employeeId = person.personId, employeeName = person.personName, employeeAge = person.personAge )
These classes cannot be mapped implicitly, because there is ambiguity in fields mapping, all four variants are valid:key = id, key = cardId, userId = id, userId = cardId