Open benjaminsnorris opened 8 years ago
Hey @benjaminsnorris -- can you try out #86 ? I added a quick test for it and it was failing on master with value(for:
. That's now working, and I'm guessing that the <|
will work, but I'm not sure.
Thanks @KingOfBrian for checking on this. It seems to still be broken. Here is an example from a quick playground I made:
//: Playground - noun: a place where people can play
import UIKit
import Marshal
let teamJSON: JSONObject = [
"name": "Engineering",
"managerId": "manager.id",
"teamMemberIds": [
"teamMember.id": true,
"secondTeamMember.id": true,
"thirdTeamMember.id": true,
],
]
struct Team: Unmarshaling {
var name: String?
var teamMemberIds = [String: Bool]()
var managerId: String?
init(object: MarshaledObject) throws {
if let teamMemberIdDictionaries: [String: Bool] = try object.value(for: "teamMemberIds") {
teamMemberIds = teamMemberIdDictionaries
} else {
teamMemberIds = [:]
}
managerId = try object <| "managerId"
name = try object <| "name"
}
}
let team = try? Team(object: teamJSON)
team?.teamMemberIds
Thanks for the snipit, that actually pointed out a bug in the non-operator code. PR coming shortly.
Just in case it's the same thing, with the latest changes, parsing [String: JSONObject]
also broke. If it's unrelated, I'll create a separate issue.
I believe that is a known issue about not supporting nested containers (#76). I believe we can fix it, but the code duplication gets painful. I'd log an issue, note #76 and see what he thinks.
Can you try out #91 @benjaminsnorris ? I think that will fix the operators, and you found a fun bug in the optional dictionary extraction which should force a new version unfortunately.
Also, just a note from your snip-it, I really like the succinctness of the ??
for optional value for's that default to an empty container.
teamMemberIds = try object.value(for: "teamMemberIds") ?? [:]
@KingOfBrian sweet! If we get this working, I would love to be able to use the succinct version of the optional parsing. That will help clean things up considerably.
@KingOfBrian unfortunately, it does not work. It parses just fine when the key is there, but when the key is not there, I get the Key not found
error.
Great catch @benjaminsnorris -- That was actually a bug, if you update that other branch it should work. I blame the cold.
whoops not sure how this got closed by that PR
We recently updated to v0.9.6, and found that some parsing is now broken. Previously, we could do
Now, I have to do something more like:
Another example is that I previously did this without problem: