Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Symfony version(s) affected
5.4.-7.2.
Description
Serializer cannot correctly serialize the same structure but with different property values.
Code:
enum DocumentType:string{caseRF_ACTUAL ='RF_ACTUAL';caseRF_PREVIOUS ='RF_PREVIOUS';}#[DiscriminatorMap('type', [ DocumentType::RF_ACTUAL->value => RussianPassportDocument::class, DocumentType::RF_PREVIOUS->value => RussianPassportDocument::class, ])]abstractclass Document{publicfunction__construct(publicDocumentType$type, ) {}}finalclass RussianPassportDocumentextends Document{publicfunction__construct(DocumentType$type) {if (!in_array($type, [DocumentType::RF_ACTUAL, DocumentType::RF_PREVIOUS])) {thrownew \InvalidArgumentException('Wrong document type'); }parent::__construct($type); }}dd($serializer->serialize([newRussianPassportDocument(DocumentType::RF_ACTUAL),newRussianPassportDocument(DocumentType::RF_PREVIOUS)],'json'),// output: [{"type":"RF_ACTUAL"},{"type":"RF_ACTUAL"}]". WTF?! 🥴$serializer->deserialize('[{"type":"RF_ACTUAL"},{"type":"RF_PREVIOUS"}]', Document::class .'[]','json'),// output: [{"type":"RF_ACTUAL"},{"type":"RF_PREVIOUS"}]. Great work 😍);
How to reproduce
Stand for reproducing the problem
Possible Solution
No response
Additional Context
No response