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 deserializing of nested snake_case attributes using CamelCaseToSnakeCaseNameConverter #51399

Conversation

Victor-Truhanovich
Copy link
Contributor

@Victor-Truhanovich Victor-Truhanovich commented Aug 16, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
License MIT

It was not possible to deserialize nested attributes using CamelCaseToSnakeCaseNameConverter

Example

readonly class Foo {
    public function __conctruct(
        #[SerializedPath("[one][two_three]")]
        public $fooBar,
    ) {
    }
}

$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$normalizer = new ObjectNormalizer($factory, new CamelCaseToSnakeCaseNameConverter());
$serializer = new Serializer([$normalizer]);

$data = [
    'one' => [
        'two_three' => 'fooBar',
    ],
];
$foo = $serializer->denormalize($data, Foo::class, 'any');

@Victor-Truhanovich
Copy link
Contributor Author

The PR was recreated because Milestone was not appointed in PR #51394

Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

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

Thank you @Victor-Truhanovich 🙂

@mtarld
Copy link
Contributor

mtarld commented Aug 22, 2023

Just one last thing, you should take care about fabbot errors: https://fabbot.io/report/symfony/symfony/51399/418bdea59c858a48dca18e493353454e16628aa1

@mtarld
Copy link
Contributor

mtarld commented Aug 22, 2023

Oh, sorry my bad, I didn't check why fabbot was yelling... Actually it's a false positive, the comments are legit here!

@Victor-Truhanovich
Copy link
Contributor Author

@mtarld I rollbacked code style changes

@nicolas-grekas nicolas-grekas force-pushed the fixed_snake_case_nested_attributes_denormalize branch from cd65d0e to f114c55 Compare August 23, 2023 10:09
@nicolas-grekas
Copy link
Member

Thank you @Victor-Truhanovich.

@nicolas-grekas nicolas-grekas merged commit bf4ea59 into symfony:6.3 Aug 23, 2023
4 of 9 checks passed
@Victor-Truhanovich Victor-Truhanovich deleted the fixed_snake_case_nested_attributes_denormalize branch August 23, 2023 12:33
@fabpot fabpot mentioned this pull request Aug 26, 2023
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

5 participants