mark-gerarts/automapper-plus

Mapping to \stdClass fails with private properties

mark-gerarts opened this issue · 1 comments

Config:

$config->registerMapping(Category::class, \stdClass::class);

Entity:

class Category
{
    private $id;

    private $name;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }
}

Mapping:

$em = $this->getDoctrine()->getRepository(Category::class);
$category = $em->findOneBy([]);
$stdclass = $this->mapper->map($category, \stdClass::class);

Expected: stdClass with ID and name properties
Actual: Cannot access private property App\Entity\Category::$id

Fixed in 693a7e5, will be included in the next release.