Commit 2f33e6e
committed
bug #46297 [Serializer] Fix JsonSerializableNormalizer ignores circular reference handler in $context (BreyndotEchse)
This PR was squashed before being merged into the 4.4 branch.
Discussion
----------
[Serializer] Fix JsonSerializableNormalizer ignores circular reference handler in $context
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| License | MIT
**How to reproduce this bug:**
Normalize an object using the default "_serializer_" service (will use "_serializer.normalizer.object_" normalizer / _ObjectNormalizer_)
```php
$target = new class {
public function getMe() { return $this; }
};
$targetData = $serializer->normalize($target, null, [
AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => static fn($v) => is_object($v) ? get_class($v) : gettype($v)
]);
// Normalized data as expected:
// $targetData === ["me" => "class@anonymous\x00 ...."];
```
Normalize an object implementing \JsonSerializable using the default "_serializer_" service (will use "_serializer.normalizer.json_serializable_" normalizer / JsonSerializableNormalizer)
```php
$target = new class implements \JsonSerializable {
public function jsonSerialize() { return ['me' => $this]; }
};
$targetData = $serializer->normalize($target, null, [
AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => static fn($v) => is_object($v) ? get_class($v) : gettype($v)
]);
// Same result expected as above, but an exception will be thrown instead:
// Symfony\Component\Serializer\Exception\CircularReferenceException("A circular reference has been detected when serializing the object of class "JsonSerializable@anonymous" (configured limit: 1).")
```
Commits
-------
793a264 [Serializer] Fix JsonSerializableNormalizer ignores circular reference handler in $contextFile tree
3 files changed
+44
-1
lines changed- src/Symfony/Component/Serializer
- Normalizer
- Tests
- Fixtures
- Normalizer
3 files changed
+44
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
99 | 117 | | |
100 | 118 | | |
101 | 119 | | |
| |||
0 commit comments