Skip to content

Add nullValueIterablePropertyMappingStrategy and nullValueMapProperty…#4068

Open
muhammadjonsaidov wants to merge 1 commit into
mapstruct:mainfrom
muhammadjonsaidov:add-null-value-iterable-map-property-mapping-strategy
Open

Add nullValueIterablePropertyMappingStrategy and nullValueMapProperty…#4068
muhammadjonsaidov wants to merge 1 commit into
mapstruct:mainfrom
muhammadjonsaidov:add-null-value-iterable-map-property-mapping-strategy

Conversation

@muhammadjonsaidov

Copy link
Copy Markdown

Changes

  • Added nullValueIterablePropertyMappingStrategy to @Mapper and @MapperConfig
  • Added nullValueMapPropertyMappingStrategy to @Mapper and @MapperConfig
  • Resolution follows the same chain as existing strategies: specific strategy
    takes precedence over nullValuePropertyMappingStrategy, which falls back
    to SET_TO_NULL by default
  • Added test covering IGNORE behavior for Iterable source properties

Example

@Mapper(
    nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL,
    nullValueIterablePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
)
public interface CustomerMapper {
    void update(Customer source, @MappingTarget CustomerDTO target);
}

When source.getItems() is null, the target's items field is left unchanged.
When source.getAddress() is null, the target's address is set to null.

Closes #3387

…MappingStrategy

Add dedicated null value property mapping strategies for Iterable and Map
source properties, analogous to the existing nullValueIterableMappingStrategy
and nullValueMapMappingStrategy. This allows fine-grained control over null
handling when a source property of Iterable or Map type is null, independent
of the general nullValuePropertyMappingStrategy.

Closes mapstruct#3387

Signed-off-by: Muhammadjon Saidov <javascript0222@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant