public function decode($json, $schema = null)
    {
        if (self::ASSOC_ARRAY === $this->objectDecoding && null !== $schema) {
            throw new \InvalidArgumentException(
                'Schema validation is not supported when objects are decoded '.
                'as associative arrays. Call '.
                'JsonDecoder::setObjectDecoding(JsonDecoder::JSON_OBJECT) to fix.'
            );
        }

        $decoded = $this->decodeJson($json);

        if (null !== $schema) {
            $errors = $this->validator->validate($decoded, $schema);

            if (count($errors) > 0) {
                throw ValidationFailedException::fromErrors($errors);
            }
        }

        return $decoded;
    }