Skip to content

Commit

Permalink
Relax JSONResponseSerializer Sendable Requirement (Alamofire#3903)
Browse files Browse the repository at this point in the history
### Issue Link 🔗
Alamofire#3902 

### Goals ⚽
This PR relaxes the `Sendable` requirement in the value returned from
`JSONResponseSerialization`, as it breaks downstream consumers still
using `Any`.

### Implementation Details 🚧
Reverted the type returned from `JSONResponseSerializer` from `any Any &
Sendable` to just `Any`.

### Testing Details 🔍
Tests updated.
  • Loading branch information
jshier authored Oct 14, 2024
1 parent 229b1a2 commit 232531d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ jobs:
- name: Clone
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: swift
- name: Build macOS
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DataRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public class DataRequest: Request, @unchecked Sendable {
emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods,
options: JSONSerialization.ReadingOptions = .allowFragments,
completionHandler: @Sendable @escaping (AFDataResponse<any Any & Sendable>) -> Void) -> Self {
completionHandler: @Sendable @escaping (AFDataResponse<Any>) -> Void) -> Self {
response(queue: queue,
responseSerializer: JSONResponseSerializer(dataPreprocessor: dataPreprocessor,
emptyResponseCodes: emptyResponseCodes,
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DownloadRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public final class DownloadRequest: Request, @unchecked Sendable {
emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods,
options: JSONSerialization.ReadingOptions = .allowFragments,
completionHandler: @Sendable @escaping (AFDownloadResponse<any Any & Sendable>) -> Void) -> Self {
completionHandler: @Sendable @escaping (AFDownloadResponse<Any>) -> Void) -> Self {
response(queue: queue,
responseSerializer: JSONResponseSerializer(dataPreprocessor: dataPreprocessor,
emptyResponseCodes: emptyResponseCodes,
Expand Down
2 changes: 1 addition & 1 deletion Source/Features/ResponseSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public final class JSONResponseSerializer: ResponseSerializer {
self.options = options
}

public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: (any Error)?) throws -> any Any & Sendable {
public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: (any Error)?) throws -> Any {
guard error == nil else { throw error! }

guard var data, !data.isEmpty else {
Expand Down
8 changes: 4 additions & 4 deletions Tests/ResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ final class ResponseJSONTestCase: BaseTestCase {
// Given
let expectation = expectation(description: "request should succeed")

var response: DataResponse<any Sendable, AFError>?
var response: DataResponse<Any, AFError>?

// When
AF.request(.default, parameters: ["foo": "bar"]).responseJSON { resp in
Expand All @@ -216,7 +216,7 @@ final class ResponseJSONTestCase: BaseTestCase {
let urlString = String.invalidURL
let expectation = expectation(description: "request should fail")

var response: DataResponse<any Sendable, AFError>?
var response: DataResponse<Any, AFError>?

// When
AF.request(urlString, parameters: ["foo": "bar"]).responseJSON { resp in
Expand All @@ -240,7 +240,7 @@ final class ResponseJSONTestCase: BaseTestCase {
// Given
let expectation = expectation(description: "request should succeed")

var response: DataResponse<any Sendable, AFError>?
var response: DataResponse<Any, AFError>?

// When
AF.request(.default, parameters: ["foo": "bar"]).responseJSON { resp in
Expand Down Expand Up @@ -272,7 +272,7 @@ final class ResponseJSONTestCase: BaseTestCase {
// Given
let expectation = expectation(description: "request should succeed")

var response: DataResponse<any Sendable, AFError>?
var response: DataResponse<Any, AFError>?

// When
AF.request(.method(.post), parameters: ["foo": "bar"]).responseJSON { resp in
Expand Down

0 comments on commit 232531d

Please sign in to comment.