@@ -177,38 +177,26 @@ public class BSONDecoder {
177177 }
178178 }
179179
180- // TODO: SWIFT-930 Implement this
181- // /**
182- // * Decodes a top-level value of the given type from the given JSON/extended JSON string.
183- // *
184- // * - Parameter type: The type of the value to decode.
185- // * - Parameter json: The JSON string to decode from.
186- // * - Returns: A value of the requested type.
187- // * - Throws: `DecodingError` if the JSON data is corrupt or if any value throws an error during decoding.
188- // */
189- // public func decode<T: Decodable>(_: T.Type, from json: String) throws -> T {
190- // // we nest the input JSON in another object, and then decode to a `DecodableWrapper`
191- // // wrapping an object of the requested type. since our decoder only supports decoding
192- // // objects, this allows us to additionally handle decoding to primitive types like a
193- // // `String` or an `Int`.
194- // // while this is not needed to decode JSON representing objects, it is difficult to
195- // // determine when JSON represents an object vs. a primitive value -- for example,
196- // // {"$numberInt": "42"} is a JSON object and looks like an object type but is actually
197- // // a primitive type, Int32. so for simplicity, we just always assume wrapping is needed,
198- // // and pay a small performance penalty of decoding a few extra bytes.
199- // let wrapped = "{\"value\": \(json)}"
200-
201- // if let doc = try? BSONDocument(fromJSON: wrapped) {
202- // let s = try self.decode(DecodableWrapper<T>.self, from: doc)
203- // return s.value
204- // }
205-
206- // throw DecodingError.dataCorrupted(
207- // DecodingError.Context(
208- // codingPath: [],
209- // debugDescription: "Unable to parse JSON string \(json)"
210- // ))
211- // }
180+ /**
181+ * Decodes a top-level value of the given type from the given JSON/extended JSON string.
182+ *
183+ * - Parameter type: The type of the value to decode.
184+ * - Parameter json: The JSON string to decode from.
185+ * - Returns: A value of the requested type.
186+ * - Throws: `DecodingError` if the JSON data is corrupt or if any value throws an error during decoding.
187+ */
188+ @available ( * , deprecated, message: " Use ExtendedJSONDecoder.decode instead " )
189+ public func decode< T: Decodable > ( _: T . Type , from json: String ) throws -> T {
190+ let decoder = ExtendedJSONDecoder ( )
191+ guard let jsonData = json. data ( using: . utf8) else {
192+ throw DecodingError . dataCorrupted (
193+ DecodingError . Context (
194+ codingPath: [ ] ,
195+ debugDescription: " Unable to parse JSON string \( json) "
196+ ) )
197+ }
198+ return try decoder. decode ( T . self, from: jsonData)
199+ }
212200
213201 /// A struct to wrap a `Decodable` type, allowing us to support decoding to types that
214202 /// are not inside a wrapping object (for ex., Int or String).
0 commit comments