private function escapeObject($value) {
        if (!is_object($value)) {
            return $value;
        }
        if (isset($value->escape) && $value->escape === false) {
            return $value;
        }
        if ($value instanceof Entity) {
            $errors = $value->getErrors();
            $invalid = $value->getInvalid();
            $properties = $value->visibleProperties();
            foreach ($properties as $prop) {
                // To not use the entity setter
                $value->set($prop, $this->escape($value->{$prop}), ['setter' => false]);
            }
            foreach($errors as $field => $err) {
                $value->setError($field, $err);
            }
            $value->setInvalid($invalid);
            return $value;
        }

        if ($this->hasIterator($value)) {
            foreach ($value as $key => $prop) {
                $value->{$key} = $this->escape($prop);
            }
            return $value;
        }

        return $value;
    }