Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created March 15, 2013 13:03
Show Gist options
  • Save mathiasverraes/5169746 to your computer and use it in GitHub Desktop.
Save mathiasverraes/5169746 to your computer and use it in GitHub Desktop.
JMSSerializer PassThroughNamingStrategy
<?php
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
use JMS\Serializer\Metadata\PropertyMetadata;
class PassThroughNamingStrategy implements PropertyNamingStrategyInterface
{
/**
* Translates the name of the property to the serialized version.
*
* @param PropertyMetadata $property
*
* @return string
*/
public function translateName(PropertyMetadata $property)
{
return $property->name;
}
}
<?php
SerializerBuilder::create()
// By default JMSSerializer converts camelCase to under_score for properties. This uses passthrough instead, leaving the properties as is.
->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new PassThroughNamingStrategy()))
->build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment