protected function addViolationToOutput(array $errors, ConstraintViolationInterface $violation)
    {
        $path = $this->getPropertyPathAsArray($violation);

        // Drill into errors and find where the error message should be added, building nonexistent portions of the path
        $currentPointer = &$errors;

        while (count($path) > 0) {
            $currentField = array_shift($path);

            if (! array_key_exists($currentField, $currentPointer) or ! is_array($currentPointer[$currentField])) {
                $currentPointer[$currentField] = [];
            }

            if (is_numeric($currentField)) {
                for ($i = 0; $i < (int) $currentField; $i++) {
                    if (! array_key_exists($i, $currentPointer)) {
                        $currentPointer[(int) $i] = null;
                    }
                }

                // Sort the elements of this array so JsonResponse converts this to an array rather than an object
                ksort($currentPointer);
            }

            $currentPointer = &$currentPointer[$currentField];
        }

        $currentPointer[] = $violation->getMessage();

        return $errors;
    }