Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] Named serializer should get correct normalizer instance#59627

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ruudk wants to merge1 commit intosymfony:7.2
base:7.2
Choose a base branch
Loading
fromruudk:ruudk/2025/1/fix-mime-message-normalizer

Conversation

ruudk
Copy link
Contributor

@ruudkruudk commentedJan 27, 2025
edited
Loading

QA
Branch?7.2
Bug fix?yes
New feature?no
Deprecations?no
Issues
LicenseMIT

Named serializers were introduced in#56823 and they work great.

We noticed a small bug when using custom name convertors.

The MimeMessageNormalizer holds a reference toserializer.normalizer.property.
But when using named serializers, it should use the specific child normalizer instead.

With this change, we fix this problem for any service that starts withserializer.normalizer..

/cc@HypeMC

Named serializers were introduced insymfony#56823 and they work great.We noticed a small bug when using custom name convertors.The MimeMessageNormalizer holds a reference to `serializer.normalizer.property`.But when using named serializers, it would use the specific child normalizer instead.With this change, we fix this problem for any service that starts with `serializer.normalizer.`.
@ruudkruudkforce-pushed theruudk/2025/1/fix-mime-message-normalizer branch from93ca946 toe0caeb7CompareJanuary 27, 2025 11:12
@ruudkruudk changed the titleNamed serializer should get correct normalizer instance[Serializer] Named serializer should get correct normalizer instanceJan 27, 2025
foreach ($container->getDefinition($id)->getArguments() as $index => $argument) {
if ($argument instanceof Reference && self::NAME_CONVERTER_METADATA_AWARE_ID === (string) $argument) {
$definition->replaceArgument($index, new Reference($config['name_converter']));
} elseif ($argument instanceof Reference && str_starts_with((string) $argument, 'serializer.normalizer.')) {
Copy link
Member

Choose a reason for hiding this comment

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

@ruudk This won't work since the service is not tagged withserializer.normalizer:

->set('serializer.normalizer.property', PropertyNormalizer::class)
->args([
service('serializer.mapping.class_metadata_factory'),
service('serializer.name_converter.metadata_aware'),
service('property_info')->ignoreOnInvalid(),
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
null,
])
->set('serializer.denormalizer.array', ArrayDenormalizer::class)

Without the tag, the child service will never be created. As far as I can tell, the service was intentionally not tagged, but I could be wrong, see#37847.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Weird because this fix does solve the problem.

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure? I've tested the fix on a clean install and got an error:

framework:serializer:named_serializers:foo:name_converter:serializer.name_converter.camel_case_to_snake_case
The service "serializer.normalizer.mime_message.foo" has a dependency on a non-existent service "serializer.normalizer.property.foo".

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Oops, you're right. For some reason, the project where we experience this problem, had the following compiler pass:

$container->addCompilerPass(newclass()implements CompilerPassInterface {publicfunctionprocess(ContainerBuilder$container) :void                {$container->getDefinition('serializer.normalizer.property')                        ->addTag('serializer.normalizer', ['priority' => -990,                        ]);                }            },            priority:10,        );

I cannot recall why we added this, but probably to make sure serialization worked the same way as JMS Serializer.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I know why we added this, because we want to use the PropertyNormalizer to make sure no getters are called while serializing. We only want properties to be serialized.

Is there a better way to enable this? Or is the compiler pass above the recommended way to use this normalizer?

Maybe we can check in this PR if theserializer.normalizer.*.$serializer_name exists, and then replace it?

@carsonbotcarsonbot changed the title[Serializer] Named serializer should get correct normalizer instanceNamed serializer should get correct normalizer instanceFeb 10, 2025
@carsonbotcarsonbot changed the titleNamed serializer should get correct normalizer instance[Serializer] Named serializer should get correct normalizer instanceFeb 11, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@HypeMCHypeMCHypeMC left review comments

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.2
Development

Successfully merging this pull request may close these issues.

5 participants
@ruudk@HypeMC@nicolas-grekas@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp