Problem with restoring data
Opened this issue · 4 comments
I have a custom data structure, with DM_ModelRoot as root item. Writing to a JSON string is working fine:
let map = Map()
var settableRoot: DM_ModelRoot? = self.modelRoot
try settableRoot ~> map["modelRoot"]
print(settableRoot)
var jsonString = map.toJson.serialize()
However, when trying to restore the JSON string, there is an error UnableToMap(.KeyPath(modelRoot), Genome.SequenceError.FoundNil("Key: .KeyPath(identifier) TargetType: String"))
:
var settableRoot: DM_ModelRoot?
let json = try Json.deserialize(jsonString)
let map = Map(json: json)
try settableRoot <~ map["modelRoot"]
What am I doing wrong?
Note: DM_ModelRoot is setup with init(...) and sequence(...) properly, the JSON string is created correctly.
BTW: It would be helpful to have examples for correctly reading and writing JSON from and into custom objects on the documentation page ;-)
BTW: There seems to be a bug in the error message - shouldn't identifier
be a value?
FoundNil("Key: .KeyPath(identifier) TargetType: String")
@innoreq sorry I missed this one, and I'm getting here so late. Can you post the model code?
Thanks for your feedback. Unfortunately, I cannot reconstruct the problem anymore, as we changed from JSON to a database solution in the meantime.
@innoreq thanks, I'll close this for now.