thoughtbot/Argo

Incorrectly parsing numbers as `Null` under Linux

Open

#455 ouverte le 17 avr. 2017

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)Swift (214 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (3 455 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Sample JSON

{
  "aggregations": {
    "my_aggregation": {
      "value": 9
    }
  }
}

Models

let int: Decoded<Int> = json <| ["aggregations", "device_count", "value"]
// ^ missingKey("value")

Argo Version

4.1.2

Dependency Manager

Swift Package Manager.


This only occurs under Linux. Locally, there's no problem on MacOS. Under the debugger it seemed to be showing that value was present but its value was null, as if {"value": null}.

Resolved this way (ugh).

let dict = json as? [String:Any]

let int = dict.flatMap({ d -> Any? in
    return d["aggregations"]
}).flatMap({  d -> [String:Any]? in
    return d as? [String:Any]
}).flatMap({ d -> Any? in
    return d["my_aggregation"]
}).flatMap({ d -> [String:Any]? in
   return d as? [String:Any]
}).flatMap({ d -> Any? in
    return d["value"]
}).flatMap({ d -> Int? in
   return d as? Int
})

I assume this is related to NSNumber being a shitshow on Linux, and thus isn't really Argo's problem. This issue is more for the benefit of everyone else.

(Related observation: if NSNumber's crufty addition of so many features is due to years of the "benefits" of ABI stability, I'm terrified for the consequences of Swift 5).

Guide contributeur