Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Serializer should throw NotNormalizableValueException instead of InvalidArgumentException when an invalid enum is deserialized #49711

Closed
@ludekbenedik

Description

@ludekbenedik

Description

Hi,
when deserialize data to an entity with an enum attribute and data contains an invalid enum 's value, the serializer throwsInvalidArgumentException which is a logic exception.

  1. This is not a program logic error soInvalidArgumentException is not correct.
  2. InvalidArgumentException is very a common exception so catching it is very difficult. A programmer must test the exception's message if an other logic exception have to be threw and logged.

For example, when deserialize a wrong date format thenNotNormalizableValueException is thrown. For a programmer these situations are equal.

Example

enum MyEnum:int{case A =0;case B =1;}class MyEntity{publicMyEnum$myEnum;}$entity =$serializer->deserialize('{"myEnum":2}', MyEntity::class,'json')

Before:

ThrowsInvalidArgumentException

After:

ThrowsNotNormalizableValueException

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp