BSONDecoder
public class BSONDecoder
BSONDecoder
facilitates the decoding of BSON into semantic Decodable
types.
-
Enum representing the various strategies for decoding
Date
s from BSON.As per the BSON specification, the default strategy is to decode
Date
s from BSON datetime objects.See also
bsonspec.orgDeclaration
Swift
public enum DateDecodingStrategy
-
Enum representing the various strategies for decoding
UUID
s from BSON.As per the BSON specification, the default strategy is to decode
UUID
s from BSON binary types with the UUID subtype.See also
bsonspec.orgDeclaration
Swift
public enum UUIDDecodingStrategy
-
Enum representing the various strategies for decoding
Data
s from BSON.As per the BSON specification, the default strategy is to decode
Data
s from BSON binary types with the generic binary subtype.See also
bsonspec.orgDeclaration
Swift
public enum DataDecodingStrategy
-
Contextual user-provided information for use during decoding.
Declaration
Swift
public var userInfo: [CodingUserInfoKey : Any]
-
The strategy used for decoding
Date
s with this instance.Declaration
Swift
public var dateDecodingStrategy: DateDecodingStrategy
-
The strategy used for decoding
UUID
s with this instance.Declaration
Swift
public var uuidDecodingStrategy: UUIDDecodingStrategy
-
The strategy used for decoding
Data
s with this instance.Declaration
Swift
public var dataDecodingStrategy: DataDecodingStrategy
-
Initializes
self
.Declaration
Swift
public init(options: CodingStrategyProvider? = nil)
-
Decodes a top-level value of the given type from the given BSON document.
Throws
DecodingError
if any value throws an error during decoding.Declaration
Swift
public func decode<T>(_ type: T.Type, from document: BSONDocument) throws -> T where T : Decodable
Parameters
type
The type of the value to decode.
document
The BSON document to decode from.
Return Value
A value of the requested type.
-
Decodes a top-level value of the given type from the given BSON data.
Throws
DecodingError
if the BSON data is corrupt or if any value throws an error during decoding.Declaration
Swift
public func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable
Parameters
type
The type of the value to decode.
data
The BSON data to decode from.
Return Value
A value of the requested type.
-
Decodes a top-level value of the given type from the given JSON/extended JSON string.
Throws
DecodingError
if the JSON data is corrupt or if any value throws an error during decoding.Declaration
Swift
@available(*, deprecated, message: "Use ExtendedJSONDecoder.decode instead") public func decode<T>(_: T.Type, from json: String) throws -> T where T : Decodable
Parameters
type
The type of the value to decode.
json
The JSON string to decode from.
Return Value
A value of the requested type.