I have a kotlin data class with default values and when I try to map it using MapStruct it throws an error at runtime because it will try to assign a null value to a non-nullable type for a property with a default value. I'm aware of assigning default values in @Mapping annotation but is there a way for MapStruct to take data class default value into consideration rather than me having to do it twice?
Here's the example:
data class A(val property1: String = "prop 1", val property2: String)
data class B(val property2: String)
@Mapper
interface SomeMapper {
...
fun mapBtoA(b: B): A
}
val b = B("prop 2 val")
val a: A = SomeMapper.INSTANCE.mapBtoA(b)
In the above example it will try to assign null to property1 instead of prop 1 default value.