-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Serializer] Add SnakeCaseToCamelCaseNameConverter
#20160
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
Conversation
components/serializer.rst
Outdated
$normalizer->normalize($kevin); | ||
// ['first_name' => 'Kévin']; | ||
|
||
$anne = $normalizer->denormalize(['first_name' => 'Anne'], 'Person'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
SnakeCaseToCamelCaseNameConverter
89c84d5
to
4303a89
Compare
4303a89
to
1a9afff
Compare
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 |
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it's for camel_cased public properties and getters/setters (Eloquent-like).
Hi! We've rewritten the Serializer documentation. In this process, we've merged the contents of the component and framework documentation. Do you have time to update this PR to instead document this new feature in https://symfony.com/doc/current/serializer.html#camelcase-to-snake-case ? No worries if you can't make the change, we can always take over this PR and make this change. |
Hi, I opened a new PR based on new merged content: #20774 |
Document symfony/symfony#58060
and closes #20151