rekalogika / mapper

An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.
MIT License
26 stars 1 forks source link

[Bug] Mapping object to `stdClass` loses explicetly set nullable property since `1.9.0` #198

Closed ToshY closed 3 weeks ago

ToshY commented 3 weeks ago

Problem

Since 1.9.0 (using 1.9.2 currently) the mapper stopped mapping nullable property values to stdClass.

Reproduction

class Book
{
    public function __construct(
        public int $id,
        public ?int $completed,
    ) {
    }
}

Then calling the mapper:

$result = $this->mapper->map(
    new Book(1, null),
    new \stdClass(),
);

In =<1.8.0:

^ {#546
  +"id": 1
  +"completed": null
}

In >=1.9.0:

^ {#547
  +"id": 1
}
priyadi commented 3 weeks ago

Should be fixed by https://github.com/rekalogika/mapper/pull/199 and v1.9.3. Thank you for your report.

ToshY commented 3 weeks ago

@priyadi Thanks for the fast fix as always 💯