Confusion about NullValueMappingStrategy vs NullValuePropertyMappingStrategy #3873
Replies: 3 comments 1 reply
-
|
Your understanding is correct. The |
Beta Was this translation helpful? Give feedback.
-
|
@filiphr One point that puzzles me is that since they have already been clearly defined, why in the issues I mentioned above, such as issue 2843 and 3390, your comments did not mention this but instead provided other solutions or regarded them as bugs. I even think they might all be closed. |
Beta Was this translation helpful? Give feedback.
-
|
@filiphr Perhaps the term "direct assignment" is too confusing. I guess what you mean is that if it's method assignment, then this strategy will precisely work. There are even new users constantly finding these issues and commenting because they have the same misunderstanding. I reviewed the comments for issue 2843 and related issues. I think they can no longer be advanced. Maybe just explain the correct usage of the two strategies and then close them. docs should also be updated and indicate this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Issue Description
After reviewing some issues, I've noticed significant confusion regarding the scope and applicability of
NullValueMappingStrategyandNullValuePropertyMappingStrategy. Those issues can be roughly divided into three categories:Some user use
NullValueMappingStrategyexpecting it to handle null properties within a source bean, when it actually only handles cases where the entire source object is null. issues: 2843Others use
NullValuePropertyMappingStrategywith regular mapping methods, not realizing it only applies to update methods (those annotated with@MappingTarget). issues: 3390NullValuePropertyMappingStrategy#SET_TO_DEFAULT, there is indeed a bug, I have make a PR. issues: 2531Actual Effect Of The Code
Based on the documentation, code comments and test:
NullValueMappingStrategy
Bean、Iterables / Arrays、Maps)RETURN_NULL: Returns null (default)RETURN_DEFAULT: Returns a "empty" instance of the target typeNullValuePropertyMappingStrategy
SET_TO_NULL: Sets the target property to null (default)SET_TO_DEFAULT: Sets the target property to its default value (empty collection, empty string, 0, etc.). But have a bug now.IGNORE: Preserves the existing value in the target@MappingTarget)Somethings to discuss
I think there is a big deviation between the actual implementation of the code and user expectations.
The community also seems to consider it a bug (but maybe it's by design?)
Change the design of NullValueMappingStrategy to support bean properties?
Add special instructions to the document?
or other
@filiphr How do you think? Some background information #1273 (comment)
Beta Was this translation helpful? Give feedback.
All reactions