- Decoded typed dictionaries now filter out invalid objects by default instead of failing the whole response. This aligns with the defaults of how arrays are decoded.
- Typed dictionaries and array functions now allow for specifiying the behaviour of when a child item encounters an error. See InvalidItemBehaviour for more details. The default is to remove these child items with
.remove - DecodingError has been restructured, so that every error provides:
- dictionary
- keypath
- expectedType
- value
- optional array if the error occured within an array
- Each DecodingError type has also been moved into a simple reason enum. JSONPrimitiveConvertibleError has also been merged into DecodingError, which now as the following error reasons:
- keyNotFound
- incorrectRawRepresentableRawValue
- incorrectType
- conversionFailure
[String: RawRepresentable]can be now be decoded- KeyPath has changed to enum with .key(String) and .keyPath([String]) cases. It can still be initialized with a string literal, with
.representing keyPaths. - Array indexes can now also be pathed into using an int in the keyPath, e.g:
myArray.2.valueInArrayItem - Decoding Dictionaries can now have any key that conforms to JSONKey (which String does by default). So you can for example have enums as the key in a dictionary. Just make your Enum conform to JSONKey. So now you can do:
let counts: [MyEnum: Int] = try jsonDictionary.json(keyKeyPath: "counts")
Thanks to Yonas Kolb
- This adds support for decoding typed dictionaries with a String key, specifically:
[String: JSONRawType][String: JSONObjectConvertible][String: JSONPrimitiveConvertible]
Thanks to Yonas Kolb
- Added support for
URLdecoding out of the box thanks to Sam Dods
- Support for Swift 3
- Keypath access in JSON dictionaries
- Renamed function for accessing values
jsonKey(_:)tojson(atKeyPath:) - Renamed
Transformableprotocol toJSONPrimitiveConvertible - Renamed
Decodableprotocol toJSONObjectConvertible - Renamed JSONDictionary loading functions:
fromFile(_:)tofrom(filename:)fromData(_:)tofrom(jsonData:)
- Added suppport for decoding arrays of
RawRepresentableenums, i.e.[RawRepresentable]
- Added suppport for
RawRepresentableenums thanks to Yonas Kolb
- Added support for decoding an array of
Tranformablevalues
- Added support for decoding a raw JSON dictionary and an array of raw JSON dictionary, i.e.
[String : AnyObject]and[[String : AnyObject]]
- Added
Tranformableprotocol to support decoding for custom types
- Renamed
MandatoryLiteralenum inDecodingErrortoMandatoryKeyNotFoundfor clarity
- API now uses a functional approach.
JSONDecoderclass and its associated methods have been replaced by anextensiononDictionary. The JSON key is now decoded by calling thejsonKey(_:)function. e.g.:
let jsonDictionary = [
"key": "value",
"key2": "value2"
]
let myStringValue : String? = jsonDictionary.jsonKey("key")
print(myStringValue) // "Optional("value")\n"