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

[Serializer] fix nullable int cannot be serialized #52885

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

nikophil
Copy link
Contributor

@nikophil nikophil commented Dec 4, 2023

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

Hello,

previous to this PR such XML could be deserialized correctly, setting null in the value:

<?xml version="1.0" encoding="UTF-8"?>
<DummyNullableInt>
	<value/>
</DummyNullableInt>
class DummyNullableInt
{
    public function __construct(
        public int|null $value = null
    )
    {}
}

but now it creates the following error:

Uninitialized string offset 0

/home/nikophil/works/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:495
/home/nikophil/works/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:630
/home/nikophil/works/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php:377
/home/nikophil/works/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:246
/home/nikophil/works/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:346

I looked for any issue or PR mentioning this problem, but couldn't find it. So here is a fix

ping @Jeroeny

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "6.4".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@nikophil nikophil changed the base branch from 7.1 to 6.4 December 4, 2023 10:54
@xabbuh xabbuh modified the milestones: 7.1, 6.4 Dec 4, 2023
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's for 5.4 I suppose?
can you please rebase + retarget?

@nikophil nikophil changed the base branch from 6.4 to 5.4 December 4, 2023 11:56
@nikophil
Copy link
Contributor Author

nikophil commented Dec 4, 2023

@nicolas-grekas done

the problem only occurs with nullable types properties, hence the @requires PHP 8 tag

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 5.4 Dec 4, 2023
@nicolas-grekas nicolas-grekas changed the title [Serializer] fix regression in 6.4 where nullable int cannot be serialized [Serializer] fix nullable int cannot be serialized Dec 4, 2023
@nicolas-grekas
Copy link
Member

Thank you @nikophil.

@nicolas-grekas nicolas-grekas merged commit a0b3913 into symfony:5.4 Dec 4, 2023
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants