Hello,
Great work on the library - nice to see something utilising KSP.
I'm just wondering how we can utilise custom Type Converters. I would like to do this due to a custom enum to data class mapping.
@Mapper(
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
)
abstract class DocumentMapper {
@Mappings(
Mapping(source = "type", target = "type", qualifiedByName = ["documentType"]),
Mapping(source = "number", target = "number"),
Mapping(source = "country", target = "country"),
)
abstract fun map(document: com.lhv.protobuf.idv.v1.type.session.Document): SessionDocument
@Named("documentType")
fun documentType(type: DocumentType): com.lhv.capplat.veriff.model.decision.DocumentType {
return when (type) {
DocumentType.DOCUMENT_TYPE_PASSPORT -> com.lhv.capplat.veriff.model.decision.DocumentType.PASSPORT
DocumentType.DOCUMENT_TYPE_ID_CARD -> com.lhv.capplat.veriff.model.decision.DocumentType.ID_CARD
DocumentType.DOCUMENT_TYPE_RESIDENCE_PERMIT -> com.lhv.capplat.veriff.model.decision.DocumentType.RESIDENCE_PERMIT
DocumentType.DOCUMENT_TYPE_DRIVERS_LICENSE -> com.lhv.capplat.veriff.model.decision.DocumentType.DRIVERS_LICENSE
DocumentType.DOCUMENT_TYPE_VISA -> com.lhv.capplat.veriff.model.decision.DocumentType.VISA
DocumentType.DOCUMENT_TYPE_TAX_STATEMENT -> com.lhv.capplat.veriff.model.decision.DocumentType.fromValue("TAX_STATEMENT")
else -> com.lhv.capplat.veriff.model.decision.DocumentType.OTHER
}
}
}
In this case documentType maps from an enum DocumentType to a plain data class (also called document type)
The documentation simply reads:
Therefore, Konvert [provides a lot of TypeConverter](https://mcarleio.github.io/konvert/typeconverter/provided) in the [konvert-converter module](https://mcarleio.github.io/konvert/modules). You can even simply create your own (little) library with a collection of custom TypeConverter and provide them to Konvert during KSP (TODO: document).
From my understanding from the documentation that's there I would need to:
- Create a new library that depends on konvert-converter-api, lets call this
my-custom-library
- Create an instance of a Type Converter for my custom mapping
- In the upstream mapping library add it to the classpath with implementation(project(:"my-custom-library")
- Konvert will detect mappings of this type and automatically apply the custom mapper
Hello,
Great work on the library - nice to see something utilising KSP.
I'm just wondering how we can utilise custom Type Converters. I would like to do this due to a custom enum to data class mapping.
@Mapper( collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, ) abstract class DocumentMapper { @Mappings( Mapping(source = "type", target = "type", qualifiedByName = ["documentType"]), Mapping(source = "number", target = "number"), Mapping(source = "country", target = "country"), ) abstract fun map(document: com.lhv.protobuf.idv.v1.type.session.Document): SessionDocument @Named("documentType") fun documentType(type: DocumentType): com.lhv.capplat.veriff.model.decision.DocumentType { return when (type) { DocumentType.DOCUMENT_TYPE_PASSPORT -> com.lhv.capplat.veriff.model.decision.DocumentType.PASSPORT DocumentType.DOCUMENT_TYPE_ID_CARD -> com.lhv.capplat.veriff.model.decision.DocumentType.ID_CARD DocumentType.DOCUMENT_TYPE_RESIDENCE_PERMIT -> com.lhv.capplat.veriff.model.decision.DocumentType.RESIDENCE_PERMIT DocumentType.DOCUMENT_TYPE_DRIVERS_LICENSE -> com.lhv.capplat.veriff.model.decision.DocumentType.DRIVERS_LICENSE DocumentType.DOCUMENT_TYPE_VISA -> com.lhv.capplat.veriff.model.decision.DocumentType.VISA DocumentType.DOCUMENT_TYPE_TAX_STATEMENT -> com.lhv.capplat.veriff.model.decision.DocumentType.fromValue("TAX_STATEMENT") else -> com.lhv.capplat.veriff.model.decision.DocumentType.OTHER } } }In this case
documentTypemaps from an enumDocumentTypeto a plain data class (also called document type)The documentation simply reads:
From my understanding from the documentation that's there I would need to:
my-custom-library