-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
How to map generic types? #8
Comments
Hi @Ocramius, unfortunately type inferring for generics is not handled at all for now, I have to think about it, maybe it could be handled someday. In the meantime, the following should work: $mapper->map(MyGenericWrapper::class . '<string>', ['value' => 'who knows?']) Also, documentation is not finished at all on this topic, but note that you can use the following annotations: /**
* @template T of mixed
* …or…
* @template T // mixed is the default type
*
* You can also use advanced types:
* @template T of int|float
* @template T of SomeClass&SomeOtherClass
* @template T of string|SomeClass
* etc…
*/
class MyGenericWrapper
{
/** @var T */
public mixed $value;
} |
Thanks for clarifying! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To try out things, I attempted mapping a generic class, where the generic type parameter has not been provided:
This leads to a clear exception:
The
README.md
example is clear about generic types where the type parameter has been set:Valinor/README.md
Lines 258 to 259 in 396f64a
How would one request a
MyGenericWrapper<int>
from the mapper, as a root de-serialization target?The text was updated successfully, but these errors were encountered: