diff --git a/AlamofireObjectMapper/AlamofireObjectMapper.swift b/AlamofireObjectMapper/AlamofireObjectMapper.swift index b181e84..e69d124 100644 --- a/AlamofireObjectMapper/AlamofireObjectMapper.swift +++ b/AlamofireObjectMapper/AlamofireObjectMapper.swift @@ -105,9 +105,12 @@ extension DataRequest { let JSONObject = processResponse(request: request, response: response, data: data, keyPath: keyPath) - if let JSONObject = JSONObject, - let parsedObject = (try? Mapper(context: context, shouldIncludeNilValues: false).map(JSONObject: JSONObject)){ - return .success(parsedObject) + if let JSONObject = JSONObject { + let mapper = Mapper(context: context, shouldIncludeNilValues: false) + do { + let parsedObject = try mapper.map(JSONObject: JSONObject) + return .success(parsedObject) + } catch {} } let failureReason = "ObjectMapper failed to serialize response." @@ -163,10 +166,11 @@ extension DataRequest { } if let JSONObject = processResponse(request: request, response: response, data: data, keyPath: keyPath){ - - if let parsedObject = try? Mapper(context: context, shouldIncludeNilValues: false).mapArray(JSONObject: JSONObject){ + let mapper = Mapper(context: context, shouldIncludeNilValues: false) + do { + let parsedObject = try mapper.mapArray(JSONObject: JSONObject) return .success(parsedObject) - } + } catch {} } let failureReason = "ObjectMapper failed to serialize response." diff --git a/Package.swift b/Package.swift index d3e4f3c..ff97f9f 100644 --- a/Package.swift +++ b/Package.swift @@ -8,13 +8,19 @@ let package = Package( .library(name: "AlamofireObjectMapper", targets: ["AlamofireObjectMapper"]), ], dependencies: [ - .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "4.8.2")) + .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "4.8.2")), + .package(url: "https://github.com/tristanhimmelman/ObjectMapper.git", .upToNextMajor(from: "3.4.2")) ], targets: [ .target( name: "AlamofireObjectMapper", - dependencies: ["Alamofire"], + dependencies: ["Alamofire", "ObjectMapper"], path: "AlamofireObjectMapper" ), + .testTarget( + name: "AlamofireObjectMapperTests", + dependencies: ["AlamofireObjectMapper"], + path: "AlamofireObjectMapperTests" + ) ] ) \ No newline at end of file