Commit fd9eeac3 authored by dbourdere's avatar dbourdere 🤠

REFACTOR remove null value before sending it to rmq

parent bb0a6f34
......@@ -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");
$object = self::getInstance()->serialize($object, "json");
$array = json_decode($object, true);
self::removeEmptyValuesAndSubarrays($array);
$object = json_encode($array);
return $object;
}
public static function removeEmptyValuesAndSubarrays(&$array){
foreach($array as $k=>&$v){
if(is_array($v)){
$v=self::removeEmptyValuesAndSubarrays($v);
if(!count($v)){
unset($array[$k]);
}
}elseif(!strlen($v)){
unset($array[$k]);
}
}
return $array;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment