SmartEncodable
public protocol SmartEncodable : Encodable
Undocumented
-
The callback for when mapping is complete
Declaration
Swift
mutating func didFinishMapping()
-
The mapping relationship of decoding keys
Declaration
Swift
static func mappingForKey() -> [SmartKeyTransformer]?
-
The strategy for decoding values
Declaration
Swift
static func mappingForValue() -> [SmartValueTransformer]?
-
Undocumented
Declaration
Swift
init()
-
toDictionary(options:
Extension method) Serializes into a dictionary
Example:
struct Model: SmartCodable { var data: String static func mappingForKey() -> [SmartKeyTransformer]? { [CodingKeys.data <--- ["json_data", "alt_data"]] } }
let model = Model(data: “value”) let dict1 = model.toDictionary() // [“data”: “value”] let dict2 = model.toDictionary(useMappedKeys: true) // [“json_data”: “value”]
Declaration
Swift
public func toDictionary(options: Set<SmartEncodingOption>? = nil) -> [String : Any]?
Parameters
useMappedKeys
Determines whether to use source field names defined in
SmartKeyTransformer
during encoding.options
Optional set of encoding configuration options that control serialization behavior
Return Value
A dictionary representation of the object, or
nil
if encoding fails -
toJSONString(options:
Extension methodprettyPrint: ) Serializes into a JSON string
Declaration
Swift
public func toJSONString(options: Set<SmartEncodingOption>? = nil, prettyPrint: Bool = false) -> String?
Parameters
useMappedKeys
Whether to use the mapped key during encoding. The default value is false.
options
encoding options
prettyPrint
Whether to format print (adds line breaks in the JSON)
Return Value
JSON string