Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Closed
Labels
Description
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.
- This is not a program logic error so
InvalidArgumentExceptionis not correct. InvalidArgumentExceptionis 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