mcarleio/konvert

Allow mapping nullable fields to non nullable fields

b-heimann-senacor opened this issue · 2 comments

It looks like you cannot convert nullable fields to non nullable fields with konvert:

@KonvertTo(Bike::class)
data class BikeDto(val brand: String?)

data class Bike(val brand: String)

I would expect konvert to generate a function like this

fun BikeDto.toBike(): Bike =
   Bike(brand = brand!!)

At the moment, running mvn compile will output this error:

[ERROR] [ksp] java.util.NoSuchElementException: Could not find converter for brand -> brand: String? -> String

You have to configure this (either global or per mapping).
Have a look here: https://mcarleio.github.io/konvert/options/#available-options

konvert.enforce-not-null

This works perfectly fine, thank you!