mapWithDefault is useful to handle those cases where the source message field is expected, but might not be existed.
Example in previous firstname lastname to fullname example, both firstname and lastname is expected to be concatenated.
Firstname is not existed. Display queue show empty context and only have <null> displayed. Mapping test run-time error.
The concat function expected first parameter must feed in value, but none provided and error out.
After implement mapWithDefault:
Let’s see the queue of mapWithDefault.
Firstname’s mapWithDefault received input value “SUPPRESS” because firstname not existed. MapWithDefault mapped it with empty string value “”.
Lastname’s mapWithDefault received input value”Locke” because lastname existed and with value “Locke”. Since field is existed, so take existed value “Locke”.
General advise, if in situation where the expected field might or might not existed but is mandatory in mapping, or the source field is not primary and optional in source system, then it is advisable to include mapWithDefault. This will avoid the mapping failed badly in run-time. Remember, all input data is evil!