Commit a57c946
committed
bug symfony#61097 [Serializer] Fix normalizing objects with accessors having the same name as a property (RafaelKr)
This PR was merged into the 6.4 branch.
Discussion
----------
[Serializer] Fix normalizing objects with accessors having the same name as a property
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix symfony#61096
| License | MIT
# Notes
Although technically this is a bugfix and its pretty much an edge-case, this may affect existing projects and may alter their serialization results. So it could be a breaking change.
Edit: Also see comments below for further edge cases.
# Before/After comparison
```php
class MyClass {
private string $owner = 'foo';
private bool $isOwner = true;
public function getOwner(): string {
return $this->owner;
}
public function setOwner(string $owner): void {
$this->owner = $owner;
}
public function isOwner(): bool {
return $this->isOwner;
}
public function setIsOwner(bool $isOwner): void {
$this->isOwner = $isOwner;
}
}
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$normalizer = new ObjectNormalizer($classMetadataFactory);
$object = new MyClass();
$normalized = $normalizer->normalize($object);
```
### Before this PR
It was normalized as:
```php
[
'owner' => 'foo',
]
```
Removing the `$owner` property and getters would result in:
```php
[
'owner' => true,
]
```
### After this PR
It will be normalized as:
```php
[
'owner' => 'foo',
'isOwner' => true,
]
```
Commits
-------
7fe90ba [Serializer] Fix normalizing objects with accessors having the same name as a propertyFile tree
2 files changed
+44
-17
lines changed- src/Symfony/Component/Serializer
- Normalizer
- Tests/Normalizer
2 files changed
+44
-17
lines changedLines changed: 14 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
107 | 108 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
121 | 118 | | |
122 | 119 | | |
123 | 120 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
955 | 955 | | |
956 | 956 | | |
957 | 957 | | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
958 | 972 | | |
959 | 973 | | |
960 | 974 | | |
| |||
1297 | 1311 | | |
1298 | 1312 | | |
1299 | 1313 | | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
0 commit comments