Java / MapStruct Java Interview questions part 2
How does MapStruct handle null values during mapping?
By default, MapStruct generates null checks for object-typed source properties and nested mapping calls: if the source property is null, the corresponding target property is simply left at its default (usually null) rather than triggering a NullPointerException deep inside a chained getter call.
For a whole source object being null (the parameter to the mapping method itself), the default behavior returns null for the whole target rather than an object full of nulls, though this is configurable through NullValueMappingStrategy. For individual properties, you can also set an explicit fallback using @Mapping(target = "...", defaultValue = "..."), which is used only when the source value is null.
More Related questions...