You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think we just need to have JSONEncoder.decode<T : Decodable>(_ type: T.Type) not expectNonNullas it does today. If the value contained is indeed null, the actual decoding of the inner value will fail for non-optional types.
What we do need to do is handle unboxing the type afterwards correctly. Since the return result here is T (in which T may be optional), we might need to differentiate between the result being nil because it failed, and the result being nil because nil is valid.
Environment
Xcode 9.3
Swift 4.1
Additional Detail from JIRA
md5: d0185b472c3142092e89fd809ebaa821
Issue Description:
JSONEncoder can encode a nil single value Optional<String> as JSON "null", but JSONDecoder does is unable to interpret the null correctly.
Consider:
When the nil Optional<String> value is encoded, it is encoded as a single-value null as expected.
{"test":null}
But when decoding, an error is thrown:
Note that when switching singleValueContainer to unkeyedContainer, there is no similar error, but the encoded json then looks like: {"test":[null]}
The text was updated successfully, but these errors were encountered: