-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Using jms_serializer.cache_naming_strategy.class overrides @SerializedName annotation #397
Comments
Any update on this? |
The problem persists and is very easy to recreate, simply add jms_serializer.cache_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy to your parameters and try to use the SerializedName property |
This is what we ended up doing in the end. I guess it means that everything is clearly marked up in annotations now but it feels counter intuitive IMHO. |
It is easy to implement this. I just copied the SerializedNameAnnotationStrategy class:
namepsace Acme\ApiBundle\Serializer;
use JMS\Serializer\Metadata\PropertyMetadata;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
class ApiNamingStrategy implements PropertyNamingStrategyInterface
{
private $delegate;
public function __construct()
{
$this->delegate = new IdenticalPropertyNamingStrategy();
}
/**
* {@inheritDoc}
*/
public function translateName(PropertyMetadata $property)
{
if (null !== $name = $property->serializedName) {
return $name;
}
return $this->delegate->translateName($property);
}
}
services:
jms_serializer.cache_naming_strategy:
class: Acme\ApiBundle\Serializer\ApiNamingStrategy |
Thank you @wesnick, can confirm, works great~ |
See #445 for a solution without adding a new strategy. |
Brilliant! Great job, @wesnick ! |
I'm using jms_serializer.cache_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy to use camel case instead of underscores, but when I have this activated my SerializedName annotation directives are ignored by the serializer.
Is this a bug or is there a workaround?
Thanks!
The text was updated successfully, but these errors were encountered: