-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] fix: deserialization union type of enum #47803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,9 @@ public function denormalize($data, string $type, string $format = null, array $c | |
return $type::from($data); | ||
} catch (\ValueError $e) { | ||
throw new InvalidArgumentException('The data must belong to a backed enumeration of type '.$type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case should probably use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exception was changed here #47128 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this commit is the source of the bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yet it was also fixing a bug, please make sure that test added in #47128 keeps passing and/or that the behavior it fixed remains the expected one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All Serializer-related tests, including those in this commit, pass. |
||
} catch (\TypeError $e) { | ||
$enumBackingType = (new \ReflectionEnum($type))->getBackingType()->getName(); | ||
throw NotNormalizableValueException::createForUnexpectedDataType('The data must be of the same type as the backed enumeration of type '.$type, $data, [$enumBackingType], $context['deserialization_path'] ?? null, true); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
class DummyObjectWithUnionEnumConstructor | ||
{ | ||
public function __construct(public StringBackedEnumDummy|IntegerBackedEnumDummy $sub) | ||
{ | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will now re-throw a NotNormalizableValueException before the
DISABLE_TYPE_ENFORCEMENT
checkUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof I did not understand quite well.
Is it better not to store the NotNormalizableValueException?
Like this :