You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that the GetSetMethodNormalizer that comes with Serializer doesn't support toggling the detection and conversion of underscores from all fields provided.
I've mitigated this by creating my own subclass as follows:
class GetSetMethodNormalizer extends Base {
protected function formatAttribute($attributeName) {
return preg_replace_callback(
'/(^|_|\.)+(.)/',
function ($match) {
return ('.' === $match[1] ? '_' : '') . strtoupper($match[2]);
},
$attributeName
);
}
}
This appears to have handled things so far, but I'm wondering if it might be nice to formalize this as a setting in GetSetMethodNormalizer?
The text was updated successfully, but these errors were encountered:
This PR was merged into the 2.7 branch.
Discussion
----------
[Serializer] Name converter support
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #12212
| License | MIT
| Doc PR | symfony/symfony-docs#4692
This PR adds support for custom property naming strategies to the serializer and provides a built-in NameConverter using this new system: (CamelCase to underscore).
It handles normalization and denormalization (convert `fooBar` to `foo_bar` when serializing, then from `foo_bar` to `fooBar` when deserializing). It also has a flag to convert only some attributes.
The `setCamelizedAttributes()` is deprecated in favor of this new method (more flexible, allows to rename all attributes of a class and support deserialization) and now uses it internally.
Commits
-------
86b84a5 [Serializer] Update changelog
e14854f [Serializer] Name converter support
I noticed that the
GetSetMethodNormalizer
that comes with Serializer doesn't support toggling the detection and conversion of underscores from all fields provided.I've mitigated this by creating my own subclass as follows:
This appears to have handled things so far, but I'm wondering if it might be nice to formalize this as a setting in
GetSetMethodNormalizer
?The text was updated successfully, but these errors were encountered: