@@ -105,6 +105,22 @@ extension Optional: JSONEncodable {
105105 return NSNull ( )
106106 case . some( let wrapped as JSONEncodable ) :
107107 return wrapped. jsonValue
108+
109+ // WORKAROUND: For reasons I don't totally understand, when the underlying type is `Any`,
110+ // even though all of these conform to `JSONEncodable`, the `as JSONEncodable` above
111+ // fails, and we need to handle them individually.
112+ case . some( let wrapped as String ) :
113+ return wrapped. jsonValue
114+ case . some( let wrapped as Int ) :
115+ return wrapped. jsonValue
116+ case . some( let wrapped as Double ) :
117+ return wrapped. jsonValue
118+ case . some( let wrapped as Bool ) :
119+ return wrapped. jsonValue
120+ case . some( let wrapped as [ String : Any ? ] ) :
121+ return wrapped. jsonValue
122+ case . some( let wrapped as [ Any ? ] ) :
123+ return wrapped. jsonValue
108124 default :
109125 fatalError ( " Optional is only JSONEncodable if Wrapped is " )
110126 }
@@ -129,6 +145,16 @@ extension Dictionary: JSONEncodable {
129145 }
130146}
131147
148+ extension Dictionary : JSONDecodable {
149+ public init ( jsonValue value: JSONValue ) throws {
150+ guard let dictionary = value as? Dictionary else {
151+ throw JSONDecodingError . couldNotConvert ( value: value, to: Dictionary . self)
152+ }
153+
154+ self = dictionary
155+ }
156+ }
157+
132158extension Array : JSONEncodable {
133159 public var jsonValue : JSONValue {
134160 return map ( ) { element -> ( JSONValue ) in
0 commit comments