Skip to content

Commit e92f308

Browse files
authored
SWIFT-917 Add sketch of ExtendedJSONDecoder public API
1 parent fe3c6cf commit e92f308

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
/// `ExtendedJSONDecoder` facilitates the decoding of ExtendedJSON into `Decodable` values.
3+
public class ExtendedJSONDecoder {
4+
/// Initialize an `ExtendedJSONDecoder`.
5+
public init() {
6+
fatalError("unimplemented")
7+
}
8+
9+
/// Decodes an instance of the requested type `T` from the provided extended JSON data.
10+
/// - SeeAlso: https://docs.mongodb.com/manual/reference/mongodb-extended-json/
11+
///
12+
/// - Parameters:
13+
/// - type: Codable type to decode the input into.
14+
/// - data: `Data` which represents the JSON that will be decoded.
15+
/// - Returns: Decoded representation of the JSON input as an instance of `T`.
16+
/// - Throws: `DecodingError` if the JSON data is corrupt or if any value throws an error during decoding.
17+
public func decode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
18+
// Takes in JSON as `Data` encoded with `.utf8` and runs it through a `JSONDecoder` to get an
19+
// instance of the `JSON` enum. Then a `BSON` enum instance is created via the `JSON`.
20+
// The `BSON` is then passed through a `BSONDecoder` where it is outputted as a `T`
21+
// Data --> JSON --> BSON --> T
22+
fatalError("unimplemented")
23+
}
24+
}

0 commit comments

Comments
 (0)