# Null handling: IGNORE vs the default on a patch, and RETURN_DEFAULT on whole objects and collections --- patch(): nullValuePropertyMappingStrategy = IGNORE, applied with a patch whose components are all null --- before: email=Asha.Mehta@Example.com, nickname=ash, roles=[USER], address=12 Park Road/Pune/411001 after : email=Asha.Mehta@Example.com, nickname=ash, roles=[USER], address=12 Park Road/Pune/411001 --- replace(): the default strategy (SET_TO_NULL), same all-null patch --- before: email=Asha.Mehta@Example.com, nickname=ash, roles=[USER], address=12 Park Road/Pune/411001 after : email=null, nickname=null, roles=null, address=null --- whole objects and collections: OrderMapper (default) vs LenientOrderMapper (RETURN_DEFAULT) --- strict.toDto(null) : null lenient.toDto(null) : OrderDto[id=null, status=null, placedAt=null, lines=null, total=null] strict order, lines = null : lines=null lenient order, lines = null : lines=[] strict.toDtos(null) : null --- the generated patch() (IGNORE): every assignment is guarded --- public void patch(CustomerPatch patch, Customer customer) { if ( patch == null ) { return; } if ( patch.email() != null ) { customer.setEmail( patch.email() ); } if ( patch.nickname() != null ) { customer.setNickname( patch.nickname() ); } if ( patch.address() != null ) { if ( customer.getAddress() == null ) { customer.setAddress( new Address() ); } addressMapper.update( patch.address(), customer.getAddress() ); } if ( customer.getRoles() != null ) { Set set = patch.roles(); if ( set != null ) { customer.getRoles().clear(); customer.getRoles().addAll( set ); } } else { Set set = patch.roles(); if ( set != null ) { customer.setRoles( new LinkedHashSet( set ) ); } } }