Skip to content
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

Automatic mapping of properties #200

Closed
mnapoli opened this issue Dec 5, 2013 · 2 comments
Closed

Automatic mapping of properties #200

mnapoli opened this issue Dec 5, 2013 · 2 comments

Comments

@mnapoli
Copy link

mnapoli commented Dec 5, 2013

Hi there, first time user of this lib so maybe I'm not getting it correctly.

I'm using this lib to serialize/unserialize DTO objects to JSON (or whatever).

So instead of using json_decode and ending up with a stdClass, I'd like to use:

$dto = $serializer->deserialize($json, MyDTO::class, 'json');

And $dto would be an instance of:

class MyDTO
{
    public $id;
    public $label;
}

Doing this manually, i.e. mapping stdClass to MyDTO is pretty simple. But I'm looking for a more generic solution.

But I don't understand why I have to add annotations to my DTO to force types. I have validation on a separate level, here I just want a DTO, i.e. a stdClass but with a known schema (good for autocompletion for example).

So am I missing something, is this something possible with this library? Or is there a reason it's not?

@schmittjoh
Copy link
Owner

We might be able to infer primitive types for JSON, for XML or object types I don't see how this could work. Therefore, when you deserialize data, type information must be added through metadata (f.e. @Type) at the moment.

@goetas goetas closed this as completed Aug 21, 2016
@goetas
Copy link
Collaborator

goetas commented Aug 21, 2016

answered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants