...
 
Commits (5)
......@@ -14,7 +14,7 @@ class JsonSerializer
public static function getInstance()
{
if (self::$serializer == null) {
if (self::$serializer === null) {
$encoders = [new JsonEncoder()];
$normalizers = [
new \Symfony\Component\Serializer\Normalizer\DateTimeNormalizer(\DateTime::ISO8601),
......@@ -34,6 +34,24 @@ class JsonSerializer
*/
public static function stringify($object)
{
return self::getInstance()->serialize($object, "json");
$array = self::getInstance()->normalize($object);
$arrayfiltered = self::array_filter_recursive($array, function($v){return $v !== null;});
$jsonEncoder = new JsonEncoder();
$object = $jsonEncoder->encode($arrayfiltered, 'json');
return $object;
}
public static function array_filter_recursive($input, $callback = null)
{
foreach ($input as &$value)
{
if (is_array($value))
{
$value = self::array_filter_recursive($value, $callback);
}
}
return array_filter($input, $callback);
}
}
\ No newline at end of file