Decodable, Swift will parse any number as whatever you try to decode is as.
However, when using
(NS)JSONSerialization, it will produce a
[String: Any] output, where each value is either
NSNull at the discretion of
Foundation, I think.
JSONSerialization.data(withJSONObject:) followed by
JSONSerialization.jsonObject(with:) is not idempotent. That is, the value that you get back from the roundtrip is not guaranteed to be identical, since there is loss of information when
Foundation needs to decide whether a
Number should be treated as
Int (or really an
NSNumber instance wrapping one of those types).
But when using
Decodable there is no ambiguity since you declare your type in your decodable models.