Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing skip null fields #84

Open
camerpu opened this issue Aug 3, 2022 · 2 comments
Open

Missing skip null fields #84

camerpu opened this issue Aug 3, 2022 · 2 comments
Projects

Comments

@camerpu
Copy link

camerpu commented Aug 3, 2022

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();
@camerpu camerpu changed the title Skip null fields Missing skip null fields Aug 3, 2022
@mark-gerarts
Copy link
Owner

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.

@camerpu
Copy link
Author

camerpu commented Aug 4, 2022

Ok, thank you for the fast response and help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Release 2.0
  
Awaiting triage
Development

No branches or pull requests

2 participants