Created
March 15, 2013 13:03
-
-
Save mathiasverraes/5169746 to your computer and use it in GitHub Desktop.
JMSSerializer PassThroughNamingStrategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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