Skip to content

[Serializer] DiscriminatorMap: Improved error message #52037

Closed
@rhazen35

Description

@rhazen35

Description

Q A
Branch? 6.3
Bug Fix? no
New Feature? yes
Deprecations? no
Tickets PR 43004

Feature: [Serializer] DiscrminatorMap: Improved error message

At the moment we get a Serializer Exception when a value is not in the discrminatorMap.

Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer.php Line: 813

{
	"message": "Serializer exception: The type \"type\" is not a valid value."
}

This was merged after this issue was implemented: PR 43004

The new feature would contain extra information about the allowed values and/or a custom error message.

Example

Proposal

  1. Additional information about the allowed values:

Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer.php Line: 813

$allowedValues = implode(', ', array_keys($mapping->getTypesMapping()))

throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type "%s" is not a valid value, allowed values: %s.', $type, $allowedValues), $type, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
  1. A custom error message

I can make a PR if this is found useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)FeatureSerializerStalled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions