ObjectMapper-Plugin icon indicating copy to clipboard operation
ObjectMapper-Plugin copied to clipboard

Optional properties should be marked with `try?` instead of `try`

Open anfriis opened this issue 7 years ago • 0 comments

According to the documentation of the ObjectMapper (https://github.com/Hearst-DD/ObjectMapper), and my own findings, optional properties should be parsed from JSON -> Model with try? instead of just try, else the whole init of the object will fail.

So e.g. if the name property is optional then it should be:

init(map: Map) throws {
     name      = try? map.value("name") // optional
}

anfriis avatar May 03 '17 08:05 anfriis