diff --git a/JSON.podspec b/JSON.podspec new file mode 100644 index 0000000..8329901 --- /dev/null +++ b/JSON.podspec @@ -0,0 +1,16 @@ +Pod::Spec.new do |s| + s.name = "JSON" + s.version = "0.1.3" + s.summary = "Micro framework for easily parsing JSON." + s.description = <<-DESC + Micro framework for easily parsing JSON in Swift with rich error messages in less than 100 lines of code. + DESC + s.homepage = "https://github.com/soffes/JSON" + s.license = { :type => "MIT", :file => "LICENSE" } + s.author = { "Sam Soffes" => "sam@soff.es" } + s.ios.deployment_target = "10.0" + s.source = { :git => ".git", :tag => s.version.to_s } + s.source_files = "Sources/**/*" + s.frameworks = "Foundation" + s.swift_version = "4.1" +end diff --git a/Sources/JSON/Decoding.swift b/Sources/JSON/Decoding.swift index 332994e..10b9c8d 100644 --- a/Sources/JSON/Decoding.swift +++ b/Sources/JSON/Decoding.swift @@ -34,6 +34,6 @@ extension Dictionary where Key : StringProtocol { /// - throws: JSONDeserializationError public func decode(key: Key) throws -> [T] { let values: [JSON] = try decode(key: key) - return try values.flatMap { try T.init(json: $0) } + return try values.compactMap { try T.init(json: $0) } } } diff --git a/Tests/JSONTests/DeserializationTests.swift b/Tests/JSONTests/DeserializationTests.swift index 461eb5d..e0962fc 100644 --- a/Tests/JSONTests/DeserializationTests.swift +++ b/Tests/JSONTests/DeserializationTests.swift @@ -55,4 +55,26 @@ final class DeserializationTests: XCTestCase { XCTAssertEqual(blog, try? Blog(json: json)) } + + func testNestedErrorDeserialization() { + let dictionary: JSONDictionary = [ + "title": "My Blog", + "posts": [ + [ + "title": "Next Post", + "author": [ + "name": "Sam Soffes" + ] + ], + [ + "title": 1, + "author": [ + "name": "Sam Soffes" + ] + ] + ] + ] + + XCTAssertThrowsError(try decode(dictionary) as Blog) + } }