JSONResponseSerializer
public final class JSONResponseSerializer : ResponseSerializer
A ResponseSerializer that decodes the response data using JSONSerialization. By default, a request returning
nil or no data is considered an error. However, if the response is has a status code valid for empty responses
(204, 205), then an NSNull value is returned.
-
JSONSerialization.ReadingOptionsused when serializing a response.Declaration
Swift
public let options: JSONSerialization.ReadingOptions -
HTTP response codes for which empty responses are allowed.
Declaration
Swift
public let emptyResponseCodes: Set<Int> -
HTTP request methods for which empty responses are allowed.
Declaration
Swift
public let emptyRequestMethods: Set<HTTPMethod> -
Creates an instance with the provided values.
Declaration
Swift
public init(options: JSONSerialization.ReadingOptions = .allowFragments, emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods)Parameters
optionsThe options to use. Defaults to
.allowFragments.emptyResponseCodesThe HTTP response codes for which empty responses are allowed. Defaults to
[204, 205].emptyRequestMethodsThe HTTP request methods for which empty responses are allowed. Defaults to
[.head]. -
Declaration
Swift
public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) throws -> Any
View on GitHub
Install in Dash
JSONResponseSerializer Class Reference