JSONRepresentable
public protocol JSONRepresentable: JSONDeserializer
A protocol for types that deserialize themselves from JSON.
Helps reduces boilerplate for types that deserialize themselves from a single source type. Using this protocol you only have to:
- specify the
JSONRepresentationtype - implement
init(jsonData:)
For an example, see UsageTests.swift.
-
The type that represents
Self, as returned byJSONSerialization.jsonObject(with:options:).Defaults to
NSDictionaryas this protocol is mostly used on classes.Declaration
Swift
associatedtype JSONRepresentation: JSONAnyParsedObject = NSDictionary -
Deserialises
jsonDatainto an instance ofSelf.Declaration
Swift
init(jsonData: JSONRepresentation) throws
-
DeserializedExtension methodA JSONRepresentable always deserializes itself.
Declaration
Swift
typealias Deserialized = Self -
deserialize(jsonObject:)Extension methodTries casting the
JSONParsedObjecttoJSONRepresentation, and callsinit(jsonData:).Throws
JSONError.unexpectedTypewhenjsonObjectcan’t be converted. Also letsinit(jsonData:)‘s errors go through.Declaration
Swift
static func deserialize(jsonObject: JSONParsedObject) throws -> Self
View on GitHub
Install in Dash
JSONRepresentable Protocol Reference