automapper-plus
automapper-plus copied to clipboard
Missing skip null fields
Hi, I'd like to know why this overwriten function:
protected function setDestinationValue(
$destination,
string $propertyName,
$value
): void {
$this->propertyWriter->setProperty(
$destination,
$propertyName,
$value
);
}
In MapFrom.php doesn't have this check from his parent:
if ($value === null && $this->options->shouldIgnoreNullProperties()) {
return;
}
In this case, when I use mapToObject, it won't skip null fields even I configured it in options by:
->getOptions()
->ignoreNullProperties();
That's a very good question actually... It does seem I specifically added this behavior, as per this commit. The commit doesn't mention any reason, nor are there any related issues around that time. When I think about it, I have to agree with you that the expected behavior for mapFrom
should be to respect the ignoreNullProperties
option.
Since this is a BC breaking change, I'm a bit reluctant to add this to the 1.x release though. As a solution for you right this moment, I'd suggest creating your own MapFrom
operation, extend it from the library's and overwrite the setDestinationValue
method. I know this isn't ideal, but it should work for now.
Ok, thank you for the fast response and help :)