JSONTransformer
public struct JSONTransformer<Input> : Transformer where Input : Decodable, Input : Encodable
A transformer that transformers values to JSON data.
-
The output of the
JSONTransformer
. AlwaysData
.Declaration
Swift
public typealias Output = Data
-
The
JSONEncoder
used for encoding values.Declaration
Swift
public var encoder: JSONEncoder
-
The
JSONDecoder
used to decode values.Declaration
Swift
public var decoder: JSONDecoder
-
Create a new instance of
JSONTransformer
.Declaration
Swift
public init(encoder: JSONEncoder = JSONEncoder(), decoder: JSONDecoder = JSONDecoder())
Parameters
encoder
The encoder used to encode values.
decoder
The decoder used to decode values.
-
Create a new instance of
JSONTransfomer
, configuring the encoder and decoder with the provided user info dictionary.Declaration
Swift
public init(coderUserInfo userInfo: [CodingUserInfoKey : Any])
Parameters
userInfo
The user info dictionary to apply to the encoder and decoder.
-
Transformer the provided value to JSON data.
Throws
Any error thrown by the encoder.Declaration
Swift
public func transformValue(_ value: Input) throws -> Data
Parameters
value
The value to transform to JSON data.
Return Value
The JSON data.
-
Untransformer the provided JSON data.
Throws
Any error thrown by the decoder.Declaration
Swift
public func untransformValue(_ data: Data) throws -> Input
Parameters
data
The JSON data to untransform.
Return Value
The untransformed value.