Index

RBJsonObject.swift

Classes


RBJsonObject

A class of properties that provides built in JSON serialisation. Note: Only properties recognized by the Obj-C runtime can be recognized i.e. Swift nilable types such as Int? will be ignored. Note: Collection properties cannot contain elements of mixed types.

Functions

Gets a dictionary of the names of Array properties that are of a particular RBJsonObject type.
@returns The dictionary of RBJsonObject types to property names.
open class func arrayMappings() -> [String: RBJsonObject.Type]?

Gets a dictionary of the names of Dictionary properties that contain a particular RBJsonObject type.
@returns The dictionary of RBJsonObject types to property names.
open class func dictionaryMappings() -> [String: RBJsonObject.Type]?

Builds an array of objects by deserialising the given JSON data.
@param jsonData : The JSON data to deserialise.
@returns An array of deserialised objects, or nil if it could not be deserialised.
public class func objects<T: RBJsonObject>(jsonData: Data) throws -> [T]?

Builds an array of objects by deserialising the given JSON string.
@param jsonString : The JSON string to deserialise.
@returns An array of deserialised objects, or nil if it could not be deserialised.
public class func objects<T: RBJsonObject>(jsonString: String) throws -> [T]?

Builds an array of objects by using the given Array.
@param array : The Array to deserialise.
@returns An array of deserialised objects, or nil if it could not be deserialised.
public class func objects<T: RBJsonObject>(array: [[String : Any]]) -> [T]?

Serialises the value of the object to a Dictionary. The result includes recursively the values of it's children.
@returns The resulting Dictionary object.
public func dictionary() -> [String: Any]

Serialises the value of the object to Data containing the JSON representation of the object. The result includes recursively the values of it's children.
@returns The resulting JSON as a Data or nil on failure.
public func data() -> Data?

Serialises the value of the object to a JSON string. The result includes recursively the values of it's children.
@returns The resulting json string or nil on failure.
public func string() -> String?

Modify the incoming JSON value before the object is populated.
@param propertyName : The name of the property on the class.
@param value : The value for the property.
@returns The transformed value.
open func transformOnDeserialization(propertyName: String, value: Any?) -> Any?

Modify the value of a property before it is serialized.
@param propertyName : The name of the property on the class.
@param value : The value for the property.
@returns The transformed value.
open func transformOnSerialization(propertyName: String, value: Any?) -> Any?

Gets the JSON key that should be used for the given property name.
@param propertyName : The name of the property on the class.
@returns The corresponding key string (will be used in JSON serialisation/deserialisation and unwrapping).
open func jsonKey(propertyName: String) -> String

Serialise the given Date property value to a string. Default implementation uses an ISO 8601 formatted string (yyyy-MM-ddTHH:mm:ssZ).
@param date : The Date property value.
@param propertyName : The name of the property.
@returns The resulting String object.
open func dateConversion(date: Date, propertyName: String) -> String

Deserialise a date string to an Date property. Default implementation assumes an ISO 8601 formatted string (yyyy-MM-ddTHH:mm:ssZ).
@param dateString : The serialised string value.
@param propertyName : The name of the property.
@returns The resulting NSDate object.
open func dateConversion(dateString: String, propertyName: String) -> Date?

Called to allow custom manipulation and validation after deserialization. Returning false will mean the object will not be initialized (nil).
@param dictionary : The name of the property on the class.
@returns Object is valid. Returning false will return a nil object.
open func afterDeserialization(_ dictionary: [String : Any]) -> Bool