Issue
Is there a simple way to conditionally use a different source property if the first property is null? I am looking for something like this:
@Mapping(target = "myTargetProperty", source = "mySourceProperty", alternativeWhenNull = "myAltSourceProperty")
Solution
You can use defaultValue
or defaultExpression
to specify a value if the source property is null
For your specific use case you can use defaultExpression = "java(source.getAlternativeProperty())
Answered By - May Rest in Peace
Answer Checked By - Marilyn (JavaFixing Volunteer)