#3387 Add nullValueIterablePropertyMappingStrategy and nullValueMapPropertyMappingStrategy - #4093
Open
Ork2004 wants to merge 4 commits into
Open
#3387 Add nullValueIterablePropertyMappingStrategy and nullValueMapPropertyMappingStrategy#4093Ork2004 wants to merge 4 commits into
Ork2004 wants to merge 4 commits into
Conversation
…ullValueMapPropertyMappingStrategy Wire the new attributes through the DelegatingOptions chain (Mapping, BeanMapping, Mapper, MapperConfig and Default levels), following the same specific-then-general- then-next-level precedence already used for nullValueIterableMappingStrategy / nullValueMapMappingStrategy. PropertyMappingBuilder.options() now picks the strategy based on the target property's type: Map-typed properties use nullValueMapPropertyMappingStrategy, Iterable/array-typed properties use nullValueIterablePropertyMappingStrategy, everything else keeps using the general nullValuePropertyMappingStrategy.
…rategies Cover the two scenarios that matter most: the general nullValuePropertyMappingStrategy vs. the Iterable/Map-specific one on @Mapper, and the more specific @Mapping-level override taking precedence over the mapper-level container strategy.
…nullValueMapPropertyMappingStrategy Add a dedicated section to chapter-10-advanced-mapping-options.asciidoc, mirroring the existing section for nullValueIterableMappingStrategy / nullValueMapMappingStrategy, and note the new attributes in NEXT_RELEASE_CHANGELOG.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3387
Right now
nullValuePropertyMappingStrategyapplies the same way to every property,no matter what type it is. So if you want
SET_TO_DEFAULTfor yourList/Mapproperties (reset to empty instead of null) but still want a nested bean property to
just become
null, you can't set it once on the mapper — you have to repeatnullValuePropertyMappingStrategyon every single@Mappingfor everylist/map property. Not great if you have a lot of mappers.
So I added two new attributes,
nullValueIterablePropertyMappingStrategyandnullValueMapPropertyMappingStrategy, on@Mapping,@BeanMapping,@Mapperand@MapperConfig. Basically the same idea as the existingnullValueIterableMappingStrategy/nullValueMapMappingStrategy(used for the wholemethod argument), just applied at the property level instead.
What I changed:
core(with fallback to the generalnullValuePropertyMappingStrategyif you don't set them)handle the existing attributes (
MappingOptions,BeanMappingOptions,MapperOptions,MapperConfigOptions,DefaultOptions)PropertyMappingBuilder.options(), based on whether the target property is a Map,an Iterable/array, or something else
nullvaluepropertymapping.containertypeI ran all the tests and they pass (3642 tests, no failures). Also ran checkstyle and
the other checks, all good. This is my first PR here, so let me know if I did
something wrong or if you'd prefer a different approach.