ExtendedJSONEncoder
public class ExtendedJSONEncoder
Facilitates the encoding of Encodable
values into ExtendedJSON.
-
An enum representing one of the two supported string formats based on the JSON standard that describe how to represent BSON documents in JSON using standard JSON types and/or type wrapper objects.
See moreDeclaration
Swift
public enum Mode
-
Determines whether to encode to canonical or relaxed extended JSON. Default is relaxed.
Declaration
Swift
public var mode: Mode
-
Contextual user-provided information for use during encoding.
Declaration
Swift
public var userInfo: [CodingUserInfoKey : Any]
-
Initialize an
ExtendedJSONEncoder
.Declaration
Swift
public init()
-
Encodes an instance of the Encodable Type
T
into Data representing canonical or relaxed extended JSON. The value ofself.mode
will determine which format is used. If it is not set explicitly, relaxed will be used.Throws
EncodingError
if the value is corrupt or cannot be converted to valid ExtendedJSON.Declaration
Swift
public func encode<T>(_ value: T) throws -> Data where T : Encodable
Parameters
value
instance of Encodable type
T
which will be encoded.Return Value
Encoded representation of the
T
input as an instance ofData
representing ExtendedJSON. -
Encodes an instance of the Encodable Type
T
into aByteBuffer
representing canonical or relaxed extended JSON. The value ofself.mode
will determine which format is used. If it is not set explicitly, relaxed will be used.Throws
EncodingError
if the value is corrupt or cannot be converted to valid ExtendedJSON.Declaration
Swift
public func encodeBuffer<T>(_ value: T) throws -> ByteBuffer where T : Encodable
Parameters
value
instance of Encodable type
T
which will be encoded.Return Value
Encoded representation of the
T
input as an instance ofByteBuffer
representing ExtendedJSON.