protected function json_encode_recursion_internal($object, $recursionLevel = 1, $options = 0, $objects, $ocurrencias){
        $pos= array_search($object, $objects);
        $repeticiones= 1;
        if($pos !== FALSE){
            $ocurrencias[$pos]++;
            $repeticiones= $ocurrencias[$pos];
        }else{
            $objects[]= $object;
            $ocurrencias[]= 1;
        }
        if($repeticiones > $recursionLevel){            
            return FALSE;
        }else{
            if(method_exists($object, 'jsonSerialize')){                
                $vars= $object->jsonSerialize();
                foreach ($vars as $key => &$var) {
                    if(is_object($var)){
                        $rta= $this->json_encode_recursion_internal($var, $recursionLevel, $options, $objects, $ocurrencias);
                        if($rta !== FALSE){
                            $var= $rta;
                        }else{
                            unset($var);
                            unset($vars[$key]);
                        }
                    }else if(is_array($var) || $var instanceof \Traversable){
                        foreach ($var as &$item) {
                            $item= $this->json_encode_recursion_internal($item, $recursionLevel, $options, $objects, $ocurrencias);
                        }
                        //$var= json_encode_recursion_internal($var, $recursionLevel, $options, $objects, $ocurrencias);
                    }
                }
                return $vars;
            }else{
                return $object;
            }
        }    
    }