Created
December 14, 2014 15:32
-
-
Save dunglas/6e6a99626ddb9ab3fee4 to your computer and use it in GitHub Desktop.
Symfony's Serializer null handling
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 | |
<<<CONFIG | |
packages: | |
- "symfony/serializer: ~2.6" | |
CONFIG; | |
use Symfony\Component\Serializer\Serializer; | |
use Symfony\Component\Serializer\Encoder\XmlEncoder; | |
use Symfony\Component\Serializer\Encoder\JsonEncoder; | |
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; | |
$encoders = array(new XmlEncoder(), new JsonEncoder()); | |
$normalizers = array(new GetSetMethodNormalizer()); | |
$serializer = new Serializer($normalizers, $encoders); | |
class T | |
{ | |
public function getA() | |
{ | |
return null; | |
} | |
} | |
echo $serializer->serialize(new T(), 'json') . PHP_EOL; | |
// Output: {"a":null} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment