Open
Description
Symfony version(s) affected
7.3.0
Description
It appears that default values don't work with the ObjectMapper.
OptionsResolver has a method to ignore missing properties, but it seems like it shouldn't need a way to ignore properties if they have a default value.
How to reproduce
$mapper = new ObjectMapper();
$target = 'App\Dto\MyClass';
$obj = (object) ['id'=>'abc'];
$entity = $mapper->map($obj, $target);
<?php
namespace App\Dto\;
class MyClass
{
public function __construct(
public string $id,
#[Map(source: 'optional', if: 'isset')]
public ?string $optional = null,
{
}
}
PixieImportService.php on line 755:
ErrorException {#10250 ▼
#message: "Warning: Undefined property: stdClass::$optional"
#code: 0
#file: "
/home/tac/sites/mus/vendor
/symfony/object-mapper/
ObjectMapper.php
"
#line: 170
#severity: E_WARNING
trace: {▶}
Possible Solution
No response
Additional Context
No response