schmittjoh / serializer

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

Can't excludePolicy("all") on embedded or nested documents #1433

Open Pillotm opened 1 year ago

Pillotm commented 1 year ago

Bug report? yes

Steps required to reproduce the problem

  1. deserialize an object with some embedded attributes values different than BDD values

Expected Result

Not excluded attributes in embedded document are not update as expected

Actual Result

The attributes not exposed are still updated

exemple :

/** @ExclusionPolicy("all") */
class Contract{
    /**
     *
     * @Serializer\Type("App\Document\Embedded\ContractPeriod")
     * @Serializer\SerializedName("contractPeriod")
     * @Expose()
     */
    private $contractPeriod;

    /**
     *
     * @Serializer\Type("App\Document\Embedded\ContractPeriod")
     * @Serializer\SerializedName("contractPeriod")
     */
    private $testNotExposed;

**In this case we are in the main document so the not exposed value will not be updated with deserialization**
}

/** @ExclusionPolicy("all") */
class ContractPeriod {
    /**
     * @Serializer\Type("string")
     * @Serializer\SerializedName("label")
     * @Expose()
     */
    private $label;

    /**
     * @var DateTime|null
     * @Groups({"contract"})
     *
     * @ODM\Field(type="date", nullable=true)
     */
    private $otherNotExposeTest;

**In this case we are in the Embedded document and the not exposed value is always updated with deserialization**

}