Skip to content

[Serializer] Impossible to use UnwrappingDenormalizer with scalar denormalization #38983

Closed
@Sajito

Description

@Sajito

Symfony version(s) affected: 5.1.8

Description
It's impossible to denormalize into a scalar value when using the unwrap path feature, because the scalar value check is done before applying the UnwrappingDenormalizer.

How to reproduce

use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;

$result = $serializer->deserialize(
    '{"baz": "test"}',
    'string',
    'json',
    [UnwrappingDenormalizer::UNWRAP_PATH => '[baz]']
);

// expected result
// $result === "test"

// actual result
// Symfony\Component\Serializer\Exception\NotNormalizableValueException: Data expected to be of type "string" ("array" given).

Possible fix
Introduce a ScalarDenormalizer instead of checking the target type inside the Serializer class.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions