public function jsonSerialize()
    {
        $serialized = [
            'message' => $this->getPublicMessage(),
            'code' => $this->getCode(),
        ];
        if ($this->getPrevious() instanceof $this) {
            /** @var static $previous */
            $previous = $this->getPrevious();
            $serialized['previous'] = $previous->jsonSerialize();
        }
        return $serialized;
    }