protected function entityToArray($class, $object)
    {
        if (is_object($object) && get_class($object) == $class) {
            $object = $object->toArray();
        }
        return $object;
    }