schmittjoh / serializer

Library for (de-)serializing data of any complexity (supports JSON, and XML)
http://jmsyst.com/libs/serializer
MIT License
2.31k stars 591 forks source link

Missing fields are replaced with null #1543

Closed nepster-web closed 3 months ago

nepster-web commented 3 months ago
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

So I used version 3.18 in the symfony ecosystem from https://github.com/schmittjoh/JMSSerializerBundle and everything worked for me:

Suppose there is a certain entity:

class User
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
    #[JMS\Groups(['List', 'Show'])]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 45, nullable: true)]
    #[JMS\SerializedName('clientIp')]
    #[JMS\Groups(['List', 'Create', 'Show'])]
    #[Assert\Length(min: 7, max: 45)]
    private ?string $clientIp = null;
...

and next code:

$json = json_encode(['clientIp' => '127.0.0.1']);
$user = // User (from db with data {id: 1, clientIp: '127.0.0.1'})
$updatedUser= $this->getJMSSerializer()->deserialize($json, $user, 'json', $context);

$updatedUser = User {id: 1, clientIp: '127.0.0.1'}

everything is fine then I did a large-scale system update and my current version 3.28.

and the same code works differently for my $updatedUser is:

$updatedUser = User {id: null, clientIp: '127.0.0.1'}

Previously, if $json did not have some keys, they were simply skipped, but now they are replaced with null.

Is this a bug in this version or did I miss something during the update?

Expected Result

$updatedUser = User {id: 1, clientIp: '127.0.0.1'}

Actual Result

$updatedUser = User {id: null, clientIp: '127.0.0.1'}

nepster-web commented 3 months ago

seems like a false alarm. this is due to the user logic of operation object constructor