-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #54148 [Serializer] Fix object normalizer when properties has the…
… same name as their accessor (NeilPeyssard) This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Fix object normalizer when properties has the same name as their accessor | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54109 | License | MIT Hello, This PR fix a bug in object normalization when properties has the same name as their accessor. The current behavior mess up class metadata between properties and methods so the keys in the normalized format does not match the object properties, and metadata are not correctly applied (`SerializedName` in our exemple). This bug also affects versions 6.4 and 7+, but I'm not sure if we can merge this PR in these branches without refactoring. Let me know if another PR should be open for version 6.4 and 7. Commits ------- 8575199f30 [Serializer] Fix object normalizer when properties has the same name as their accessor
- Loading branch information
Showing
6 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
class SamePropertyAsMethodDummy | ||
{ | ||
private $freeTrial; | ||
private $hasSubscribe; | ||
private $getReady; | ||
private $isActive; | ||
|
||
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive) | ||
{ | ||
$this->freeTrial = $freeTrial; | ||
$this->hasSubscribe = $hasSubscribe; | ||
$this->getReady = $getReady; | ||
$this->isActive = $isActive; | ||
} | ||
|
||
public function getFreeTrial() | ||
{ | ||
return $this->freeTrial; | ||
} | ||
|
||
public function hasSubscribe() | ||
{ | ||
return $this->hasSubscribe; | ||
} | ||
|
||
public function getReady() | ||
{ | ||
return $this->getReady; | ||
} | ||
|
||
public function isActive() | ||
{ | ||
return $this->isActive; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
Tests/Fixtures/SamePropertyAsMethodWithMethodSerializedNameDummy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
use Symfony\Component\Serializer\Annotation\SerializedName; | ||
|
||
class SamePropertyAsMethodWithMethodSerializedNameDummy | ||
{ | ||
private $freeTrial; | ||
private $hasSubscribe; | ||
private $getReady; | ||
private $isActive; | ||
|
||
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive) | ||
{ | ||
$this->freeTrial = $freeTrial; | ||
$this->hasSubscribe = $hasSubscribe; | ||
$this->getReady = $getReady; | ||
$this->isActive = $isActive; | ||
} | ||
|
||
/** | ||
* @SerializedName("free_trial_method") | ||
*/ | ||
public function getFreeTrial() | ||
{ | ||
return $this->freeTrial; | ||
} | ||
|
||
/** | ||
* @SerializedName("has_subscribe_method") | ||
*/ | ||
public function hasSubscribe() | ||
{ | ||
return $this->hasSubscribe; | ||
} | ||
|
||
/** | ||
* @SerializedName("get_ready_method") | ||
*/ | ||
public function getReady() | ||
{ | ||
return $this->getReady; | ||
} | ||
|
||
/** | ||
* @SerializedName("is_active_method") | ||
*/ | ||
public function isActive() | ||
{ | ||
return $this->isActive; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Tests/Fixtures/SamePropertyAsMethodWithPropertySerializedNameDummy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
use Symfony\Component\Serializer\Annotation\SerializedName; | ||
|
||
class SamePropertyAsMethodWithPropertySerializedNameDummy | ||
{ | ||
/** | ||
* @SerializedName("free_trial_property") | ||
*/ | ||
private $freeTrial; | ||
|
||
/** | ||
* @SerializedName("has_subscribe_property") | ||
*/ | ||
private $hasSubscribe; | ||
|
||
/** | ||
* @SerializedName("get_ready_property") | ||
*/ | ||
private $getReady; | ||
|
||
/** | ||
* @SerializedName("is_active_property") | ||
*/ | ||
private $isActive; | ||
|
||
public function __construct($freeTrial, $hasSubscribe, $getReady, $isActive) | ||
{ | ||
$this->freeTrial = $freeTrial; | ||
$this->hasSubscribe = $hasSubscribe; | ||
$this->getReady = $getReady; | ||
$this->isActive = $isActive; | ||
} | ||
|
||
public function getFreeTrial() | ||
{ | ||
return $this->freeTrial; | ||
} | ||
|
||
public function hasSubscribe() | ||
{ | ||
return $this->hasSubscribe; | ||
} | ||
|
||
public function getReady() | ||
{ | ||
return $this->getReady; | ||
} | ||
|
||
public function isActive() | ||
{ | ||
return $this->isActive; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters