Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(serializer): correct supported types for elasticsearch item normalizer decorator#5769

Merged
soyuka merged 1 commit into
api-platform:3.1from
jdohuutin:fix-normalizer
Aug 28, 2023
Merged

fix(serializer): correct supported types for elasticsearch item normalizer decorator#5769
soyuka merged 1 commit into
api-platform:3.1from
jdohuutin:fix-normalizer

Conversation

@jdohuutin
Copy link
Copy Markdown
Contributor

Q A
Branch? 3.1
Tickets -
License MIT
Doc PR -

I have issue using DTO input (https://api-platform.com/docs/core/dto/#implementing-a-write-operation-with-an-input-different-from-the-resource). The state processor doesn't receive the input class as argument. There is a problem with the deserialization process.

This pull request fixes my issue.

With elasticsearch support enabled, the normalizer api_platform.elasticsearch.normalizer.item is registered, it decorates the default item normalizer api_platform.serializer.normalizer.item.

I guess that this ApiPlatform\Elasticsearch\Serializer\ItemNormalizer class intend to prevent calling the decorated service when using elasticsearch format.

Unfortunately, recent patch on the getSupportedTypes method break this.

Comment thread src/Elasticsearch/Serializer/ItemNormalizer.php
@michielkalle
Copy link
Copy Markdown
Contributor

Just discovered this issue as well!
Tested is, worked like a charm.

@soyuka soyuka merged commit c8b9741 into api-platform:3.1 Aug 28, 2023
@soyuka
Copy link
Copy Markdown
Member

soyuka commented Aug 28, 2023

Thanks!

@acaenepeel
Copy link
Copy Markdown

Since this fix I get following error: "Failed to denormalize attribute "origin" value for class "App\Document\Content": Expected argument of type "App\Document\Origin", "array" given at property path "origin".".

Any idea how to fix this?

Trace:

[
    {
        "namespace": "",
        "short_class": "",
        "class": "",
        "type": "",
        "function": "",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/serializer/Exception/NotNormalizableValueException.php",
        "line": 32,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\Serializer\\Exception",
        "short_class": "NotNormalizableValueException",
        "class": "Symfony\\Component\\Serializer\\Exception\\NotNormalizableValueException",
        "type": "::",
        "function": "createForUnexpectedDataType",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
        "line": 393,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\Serializer\\Normalizer",
        "short_class": "AbstractObjectNormalizer",
        "class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
        "type": "->",
        "function": "denormalize",
        "file": "/data/home/deploy_monkey/content-api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
        "line": 239,
        "args": []
    },
    {
        "namespace": "ApiPlatform\\Serializer",
        "short_class": "AbstractItemNormalizer",
        "class": "ApiPlatform\\Serializer\\AbstractItemNormalizer",
        "type": "->",
        "function": "denormalize",
        "file": "/data/home/deploy_monkey/content-api/vendor/api-platform/core/src/Serializer/ItemNormalizer.php",
        "line": 71,
        "args": []
    },
    {
        "namespace": "ApiPlatform\\Serializer",
        "short_class": "ItemNormalizer",
        "class": "ApiPlatform\\Serializer\\ItemNormalizer",
        "type": "->",
        "function": "denormalize",
        "file": "/data/home/deploy_monkey/content-api/vendor/api-platform/core/src/Elasticsearch/Serializer/ItemNormalizer.php",
        "line": 71,
        "args": []
    },
    {
        "namespace": "ApiPlatform\\Elasticsearch\\Serializer",
        "short_class": "ItemNormalizer",
        "class": "ApiPlatform\\Elasticsearch\\Serializer\\ItemNormalizer",
        "type": "->",
        "function": "denormalize",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/serializer/Debug/TraceableNormalizer.php",
        "line": 84,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\Serializer\\Debug",
        "short_class": "TraceableNormalizer",
        "class": "Symfony\\Component\\Serializer\\Debug\\TraceableNormalizer",
        "type": "->",
        "function": "denormalize",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/serializer/Serializer.php",
        "line": 234,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\Serializer",
        "short_class": "Serializer",
        "class": "Symfony\\Component\\Serializer\\Serializer",
        "type": "->",
        "function": "denormalize",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/serializer/Serializer.php",
        "line": 152,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\Serializer",
        "short_class": "Serializer",
        "class": "Symfony\\Component\\Serializer\\Serializer",
        "type": "->",
        "function": "deserialize",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/serializer/Debug/TraceableSerializer.php",
        "line": 62,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\Serializer\\Debug",
        "short_class": "TraceableSerializer",
        "class": "Symfony\\Component\\Serializer\\Debug\\TraceableSerializer",
        "type": "->",
        "function": "deserialize",
        "file": "/data/home/deploy_monkey/content-api/vendor/api-platform/core/src/Symfony/EventListener/DeserializeListener.php",
        "line": 101,
        "args": []
    },
    {
        "namespace": "ApiPlatform\\Symfony\\EventListener",
        "short_class": "DeserializeListener",
        "class": "ApiPlatform\\Symfony\\EventListener\\DeserializeListener",
        "type": "->",
        "function": "onKernelRequest",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
        "line": 116,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
        "short_class": "WrappedListener",
        "class": "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
        "type": "->",
        "function": "__invoke",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
        "line": 220,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\EventDispatcher",
        "short_class": "EventDispatcher",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->",
        "function": "callListeners",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/event-dispatcher/EventDispatcher.php",
        "line": 56,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\EventDispatcher",
        "short_class": "EventDispatcher",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->",
        "function": "dispatch",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
        "line": 139,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
        "short_class": "TraceableEventDispatcher",
        "class": "Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
        "type": "->",
        "function": "dispatch",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/http-kernel/HttpKernel.php",
        "line": 158,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\HttpKernel",
        "short_class": "HttpKernel",
        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
        "type": "->",
        "function": "handleRaw",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/http-kernel/HttpKernel.php",
        "line": 76,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\HttpKernel",
        "short_class": "HttpKernel",
        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
        "type": "->",
        "function": "handle",
        "file": "/data/home/deploy_monkey/content-api/vendor/symfony/http-kernel/Kernel.php",
        "line": 197,
        "args": []
    },
    {
        "namespace": "Symfony\\Component\\HttpKernel",
        "short_class": "Kernel",
        "class": "Symfony\\Component\\HttpKernel\\Kernel",
        "type": "->",
        "function": "handle",
        "file": "/data/home/deploy_monkey/content-api/public/index.php",
        "line": 28,
        "args": []
    }
]

POST data:

{
    "headline": "...",
    "subHeadline": "",
    "language": "...",
    "description": "...",
    "level": "...",
    "status": "...",
    "type": "...",
    "origin": {
        "cms": "...",
        "externalId": "...",
        "brand": "...",
        "type": "...",
        "dateCreated": "2023-09-15 04:36:15",
        "dateModified": "2023-09-15 09:23:50"
    }
}

Romaixn pushed a commit to Romaixn/core that referenced this pull request Oct 3, 2023
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

Successfully merging this pull request may close these issues.

4 participants