public function deserialize(array $serialized): DomainEvent {
        $className = $this->classNameForEvent($serialized['eventName']);

        $reflect = new ReflectionClass($className);
        $const = $reflect->getConstructor();

        // reflect on constructor to get name / type
        $constParams = [];
        foreach ($const->getParameters() as $param) {
            $constParams[] = [
                $param->getType()->getName(),
                $param->getName(),
            ];
        }

        // get the values for the constructor fields from the serialized event
        $constParamValues = [];
        foreach ($constParams as $constParam) {
            list($type, $name) = $constParam;
            $fields = $serialized['fields'];
            if ( ! isset($fields[$name])) {
                throw new \Exception("Cannot find serialized field {$name} for {$className}.");
            }
            $constParamValues[] = [
                $type,
                $name,
                $fields[$name],
            ];
        }

        // reconstruct the serialized values into the correct type
       return new $className(...array_map([$this, 'deserializeField'], $constParamValues));
    }