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

Unwrapping Denormalizer #2

Open
root-aza opened this issue Dec 23, 2024 · 1 comment
Open

Unwrapping Denormalizer #2

root-aza opened this issue Dec 23, 2024 · 1 comment

Comments

@root-aza
Copy link
Contributor

Ref https://symfony.com/blog/new-in-symfony-5-1-serializer-improvements#unwrapping-denormalizer

@SerafimArts
Copy link
Member

SerafimArts commented Dec 23, 2024

It seems like something similar could be done with custom types.

$result = $mapper->denormalize($value, 'unwrap{path: "[baz][inner]", ...<ValueType>}');

On the other hand, this is not very correct from a semantic point of view...

I'm not sure that this is a critically needed functionality. Often, such things are solved manually.

The only downside is that the mapper does not yet support array shapes, otherwise we could do:

$json = '{"baz": {"foo": "bar", "inner": {"title": "value", "numbers": [5,3]}}}';

$result = $mapper->denormalize(json_decode($json), <<<'TYPE'
    array{ 
        baz: array{
            inner: ExpectedType, 
            ...
        }
    }
    TYPE);

/** @var ExpectedType $value */
$value = $result['baz']['inner'];

For some reason it just seems to me that this is some kind of separate, full-fledged functionality that should be introduced along with embeddable (Doctrine-like) types. The only difference is in the unpacking: One (embeddables) puts data it inside other type, and the other (unwraps) outside.

P.S. If there are any suggestions on how to elegantly solve the problem - welcome))) I can only theorize for now.

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

2 participants