Hi, all, as part of its planned 0.3.0 release, swift-json
will be including a new, more-streamlined decoding API for when the compiler-generated Decodable
implementation is unsuitable, or does not offer enough control with respect to handling of null
entries.
currently we have (these are all methods on JSON.JSON
)
// i. non-optional spelling; reports mismatch with `nil`
//
@inlinable public
func `as`(_:Bool.Type) -> Bool?
// matches `true` and `false` *only*, returns `nil` for
// all other variant cases.
let _:Bool? = json.as(Bool.self)
// ii. non-optional spelling; throwing, reports mismatch with `Error`
//
@inlinable public
func `as`(_:Bool.Type) throws -> Bool
// matches `true` and `false` *only*, throws an error for
// all other variant cases.
let _:Bool = try json.as(Bool.self)
// iii. optional spelling; throwing, reports mismatch with `Error`,
// reports `null` with `nil`.
//
@inlinable public
func `as`(_:Bool?.Type) throws -> Bool?
// matches `true`, `false`, and `null`; throws an error for
// all other variant cases.
let _:Bool? = try json.as(Bool?.self)
but before committing to any particular spelling, i was wondering if anyone had any feedback they would like to share.