-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
base: 7.2
Are you sure you want to change the base?
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.
Document symfony/symfony#58060
and closes #20151