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 method

    Returns a map filled with the contents of this object

    Throws

    Throws an error if this object fails to initalize. This will mostly likely throw a MapDecodingError 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 method

    Returns a map filled with the contents of this object

    Throws

    Throws an error if this object fails to initalize. This will mostly likely throw a MapDecodingError 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 method

    Serializes this object into a JSON Data object

    Throws

    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.

  • Serializes 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.