Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions JSON.podspec
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Sources/JSON/Decoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ extension Dictionary where Key : StringProtocol {
/// - throws: JSONDeserializationError
public func decode<T: JSONDeserializable>(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) }
}
}
22 changes: 22 additions & 0 deletions Tests/JSONTests/DeserializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}