You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was merged into the 4.4 branch.
Discussion
----------
[FrameworkBundle] Lower JsonSerializableNormalizer priority
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets |
| License | MIT
| Doc PR |
IMHO, more generic normalizers, like `ObjectNormalizer` or `JsonSerializableNormalizer` should have lower priority than other more specific normalizers, like `DateTimeNormalizer`, `ConstraintViolationListNormalizer`, etc.
My issue was with `Carbon` library, which extends php's `DateTime`.
`Carbon` classes implement `JsonSerializable` interface, so they are serialized with `JsonSerializableNormalizer`, using its internal `toJSON()` method, so I can't control which format I want them to be serialized.
I should be able to do it, as I can with `DateTime`, cause both implement `DateTimeInterface`.
That's because `JsonSerializableNormalizer` has higher priority than `DateTimeNormalizer`.
For now, my "fix" was to change priority in config like so:
```yaml
serializer.normalizer.json_serializable:
class: Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer
tags:
- {name: 'serializer.normalizer', priority: -950 }
```
Commits
-------
3fcfc20 [FrameworkBundle] Lower JsonSerializableNormalizer priority
0 commit comments