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
JSONEncoderused for encoding values.Declaration
Swift
public var encoder: JSONEncoder -
The
JSONDecoderused 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
encoderThe encoder used to encode values.
decoderThe 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
userInfoThe 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 -> DataParameters
valueThe 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 -> InputParameters
dataThe JSON data to untransform.
Return Value
The untransformed value.
View on GitHub
JSONTransformer Structure Reference