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] Add SnakeCaseToCamelCaseNameConverter #20160

Open
wants to merge 1 commit into
base: 7.2
Choose a base branch
from

Conversation

thibaut22200
Copy link
Contributor

Document symfony/symfony#58060
and closes #20151

$normalizer->normalize($kevin);
// ['first_name' => 'Kévin'];

$anne = $normalizer->denormalize(['first_name' => 'Anne'], 'Person');
Copy link
Member

Choose a reason for hiding this comment

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

The example here seems to be the same as the one for the CamelCaseToSnakeCaseNameConverter. That doesn't look right to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xabbuh Fixed the example, thanks you.

@OskarStark OskarStark changed the title [Serializer] Add SnakeCaseToCamelCaseNameConverter [Serializer] Add SnakeCaseToCamelCaseNameConverter Aug 25, 2024
@xabbuh
Copy link
Member

xabbuh commented Aug 28, 2024

I think there is still some misunderstanding. When the name converter is being used the name of the property is converted but not the value. So I would expect a class with a property like $full_name and a key like fullName in the normalised data.

Comment on lines +645 to +663
class Person
{
public function __construct(
private string $fullName,
) {
}

public function getFullName(): string
{
return $this->fullName;
}
}

$john = new Person('john_doe');
$normalizer->normalize($john);
// ['full_name' => 'johnDoe'];

$john = $normalizer->denormalize(['full_name' => 'johnDoe'], 'Person');
// Person object with fullName: 'jonh_doe'
Copy link
Contributor

@OskarStark OskarStark Sep 3, 2024

Choose a reason for hiding this comment

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

Suggested change
class Person
{
public function __construct(
private string $fullName,
) {
}
public function getFullName(): string
{
return $this->fullName;
}
}
$john = new Person('john_doe');
$normalizer->normalize($john);
// ['full_name' => 'johnDoe'];
$john = $normalizer->denormalize(['full_name' => 'johnDoe'], 'Person');
// Person object with fullName: 'jonh_doe'
class Person
{
public function __construct(
private string $full_name,
) {
}
public function getFullName(): string
{
return $this->full_name;
}
}
$john = new Person('john');
$normalizer->normalize($john);
// ['fullName' => 'john'];
$john = $normalizer->denormalize(['fullName' => 'john'], 'Person');
// $john->getFullName() -> 'john'

cc @xabbuh

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if it works this way when the property is not public and the getter has a camel case name.

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.

[Serializer] Add SnakeCaseToCamelCaseNameConverter
4 participants