Skip to content
Merged
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
4 changes: 3 additions & 1 deletion Sources/Segment/Utilities/JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public enum JSON: Equatable {
self = .string(string)
case let bool as Bool:
self = .bool(bool)
case let array as [Any]:
case let aSet as Set<AnyHashable>:
self = .array(try aSet.map(JSON.init))
case let array as Array<Any>:
self = .array(try array.map(JSON.init))
case let object as [String: Any]:
self = .object(try object.mapValues(JSON.init))
Expand Down
10 changes: 10 additions & 0 deletions Tests/Segment-Tests/JSON_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ class JSONTests: XCTestCase {
}
}

func testJSONCollectionTypes() throws {
let testSet: Set = ["1", "2", "3"]
let traits = try! JSON(["type": NSNull(), "preferences": ["bwack"], "key": testSet])
let jsonSet = traits["key"]
XCTAssertNotNil(jsonSet)
let array = jsonSet!.arrayValue!
XCTAssertNotNil(array)
XCTAssertEqual(array.count, 3)
}

func testJSONNil() throws {
let traits = try JSON(["type": NSNull(), "preferences": ["bwack"], "key": nil])
let encoder = JSONEncoder()
Expand Down