-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Union types deserialisation #1504
Union types deserialisation #1504
Conversation
@scyzoryck I am using serializer pretty intensively for some SDK tasks, but I need union support to move forward. I'm very happy to contribute some development effort to get this in place. What can I do to help this PR get back on track? Would you be open to me extending this functionality to more complex types? Thanks, |
@goetas - could you take a look at it, please? :) If you agree with taking such approach for the union types, I will fix the phpstan issues. @idbentley Thanks for bringing back this MR :) For no needed, I will try to make it work after approval for the approach from Goetas :) |
I think adding these assertions would improve the tests as well:
|
case 'string': | ||
break; | ||
default: | ||
throw new RuntimeException(); |
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.
shouldn't here be a better message?
or be a map (static property in the class) with alternative names for types?
static $aliases = [
'boolean' => 'bool',
'integer' => 'int',
//...
];
public static function getSubscribingMethods() | ||
{ | ||
return [ | ||
[ |
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.
can this be shortened as in
public static function getSubscribingMethods() |
|
||
private function matchSimpleType($data, array $type, Context $context) | ||
{ | ||
$dataType = gettype($data); |
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.
i guess this works for json only... in XML all the data are always strings... so I do not see the point of this handler for xml
@@ -423,6 +425,18 @@ public static function getTypeHintedArraysAndStdClass() | |||
]; | |||
} | |||
|
|||
public function testDeserializingUnionProperties() |
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 seems doing the test with primitives... what about union of objects? is that supported?
Lets add initial support for Union types from JSON. Limitations: