Crell / Serde

Robust Serde (serialization/deserialization) library for PHP 8.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deserializing NULL values is ignored

waahhhh opened this issue · comments

Detailed description

Provide a detailed description of the change or addition you are proposing.

Make it clear if the issue is a bug, an enhancement or just a question.

Currently there is a bug that prevents nullable properties from being explicitly set to NULL.
If you use #[ClassSettings(requireValues: true)], you will receive a Crell\Serde\MissingRequiredValueWhenDeserializing error.

Context

Why is this change important to you? How would you use it?

Serde is used to map the raw data of a JSON API into an object.
It's necessary to be able to pass certain values as NULL.

How can it benefit other users?

This behavior is surely expected for other users.

Possible implementation

Not obligatory, but suggest an idea for implementing addition or change.

Passing an existing value as NULL should result in setting the property to NULL.

Your environment

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

  • Version used (e.g. PHP 5.6, HHVM 3): PHP 8.2.15 (cli) (built: Jan 20 2024 14:17:05) (NTS)
  • Operating system and version (e.g. Ubuntu 16.04, Windows 7): Ubuntu 22.04.4 LTS
  • Link to your project: https://github.com/waahhhh/serde-test

Can you provide a PR with a failing tests that I can work from?

Creating the PR takes some time, because it's not easy for me to find into the project.
Now I've found an approach. The PR will be ready shortly.