MapEncodable
public protocol MapEncodable
A protocol that adds support of complex objects to be serialized into a JSON object.
-
Fill a map with the contents of this object.
Declaration
Swift
func fill(map: Map) throws
Parameters
map
A map that needs to be filled with this object. In default implementations, this map is empty.
-
filledMap()
Extension methodReturns a map filled with the contents of this object
Throws
Throws an error if this object fails to initalize. This will mostly likely throw aMapDecodingError
but since this method is implemented by the user, it may throw any error.Declaration
Swift
func filledMap() throws -> Map
Return Value
The filled map.
-
json()
Extension methodReturns a map filled with the contents of this object
Throws
Throws an error if this object fails to initalize. This will mostly likely throw aMapDecodingError
but since this method is implemented by the user, it may throw any error.Declaration
Swift
func json() throws -> [String : Any?]
Return Value
The filled map.
-
jsonData(options:)
Extension methodSerializes this object into a JSON
Data
objectThrows
Throws an error if this object failed to serialize.Declaration
Swift
public func jsonData(options: JSONSerialization.WritingOptions = []) throws -> Data
Parameters
options
The writing options.
Return Value
The serialized object.
-
jsonString(options:encoding:)
Extension methodSerializes this object into a JSON
String
Throws
Throws an error if this object failed to serialize.Declaration
Swift
public func jsonString(options: JSONSerialization.WritingOptions = [], encoding: String.Encoding = .utf8) throws -> String?
Parameters
options
The writing options.
encoding
The string encoding that should be used.
Return Value
The serialized object.