Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serializer] Fix SerializedPath not working with constructor arguments #50193

Merged
merged 1 commit into from May 19, 2023

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented Apr 29, 2023

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Currently the #[SerializedPath] attribute doesn't work with constructor arguments:

class Test
{
    public function __construct(
        #[SerializedPath('[foo][bar]')] public string $bar,
    ) {
    }
}

$serializer->denormalize(['foo' => ['bar' => 'something']], Test::class);
In AbstractNormalizer.php line 384:
                                                                                                                                    
  Cannot create an instance of "Test" from serialized data because its constructor requires parameter "bar" to be present.  

@HypeMC HypeMC requested a review from dunglas as a code owner April 29, 2023 03:23
@carsonbot carsonbot added this to the 6.2 milestone Apr 29, 2023
@HypeMC HypeMC closed this May 6, 2023
@HypeMC HypeMC reopened this May 6, 2023
@HypeMC HypeMC force-pushed the serialized-path-in-constructor branch from e13aa7a to 0ff624c Compare May 6, 2023 17:24
@nicolas-grekas nicolas-grekas force-pushed the serialized-path-in-constructor branch from 0ff624c to 30e36ed Compare May 19, 2023 07:51
@nicolas-grekas nicolas-grekas force-pushed the serialized-path-in-constructor branch from 30e36ed to 240c031 Compare May 19, 2023 07:59
@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

@nicolas-grekas nicolas-grekas merged commit 71f8c57 into symfony:6.2 May 19, 2023
3 of 9 checks passed
@HypeMC HypeMC deleted the serialized-path-in-constructor branch May 19, 2023 08:15
This was referenced May 22, 2023
$reflectionClass = new \ReflectionClass($type);
$object = $this->instantiateObject($normalizedData, $type, $context, $reflectionClass, $allowedAttributes, $format);
$resolvedClass = $this->objectClassResolver ? ($this->objectClassResolver)($object) : $object::class;
$mappedClass = $this->getMappedClass($normalizedData, $type, $context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning this breaks code where the doctrine discriminator has no property (ie exists only in the database)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants