Commit 3f92492
committed
bug symfony#51992 [Serializer] Fix using
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[Serializer] Fix using `DateIntervalNormalizer` with union types
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| License | MIT
The union logic of `AbstractObjectNormalizer` tries to denormalize each union type and catches `NotNormalizableValueException` (among some other exceptions). If a non-catching exception is thrown, denormalization fails on that first type, while a later type might have succeeded.
If I try to denormalize a `DateTimeInterface` value into a `DateInterval|DateTimeInterface` type, it will fail because the `DateIntervalNormalizer` throws `UnexpectedValueException` instead of `NotNormalizableValueException`.
Denormalizing a `DateInterval` into `DateTimeInterface|DateInterval` does work, because `DateTimeNormalizer` throws `NotNormalizableValueException`. I also checked some other Object-specific normalizers like `Uid`, `Problem`, `DateTimeZone`, `DataUri`, `BackedEnum`, they are using `NotNormalizableValueException`.
See reproducer: https://github.com/Jeroeny/reproduce/tree/union/src
Commits
-------
c727a2f [Serializer] Fix using `DateIntervalNormalizer` with union typesDateIntervalNormalizer with union types (Jeroeny)File tree
2 files changed
+11
-12
lines changed- src/Symfony/Component/Serializer
- Normalizer
- Tests/Normalizer
2 files changed
+11
-12
lines changedLines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
| 73 | + | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
79 | | - | |
| 78 | + | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
| 82 | + | |
84 | 83 | | |
85 | 84 | | |
86 | 85 | | |
| |||
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | | - | |
| 100 | + | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
| |||
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
118 | | - | |
| 117 | + | |
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
0 commit comments