Closed AlekseiR closed 4 years ago
Say I have the following
struct ItemsExtractor<T: ImmutableMappable>: ImmutableMappable { let totalItems: Int let items: [T] init(map: Map) throws { self.totalItems = try map.value("totalItems") self.items = try map.value("items") } }
{ "object": { "totalItems": 0, "items": [] } }
struct MyModel: ImmutableMappable { let object: ItemsExtractor<SomeObject>? init(map: Map) throws { self.object = try? map.value("object") } }
It doesn't actually matter what SomeObject looks like in this case, but..
struct SomeObject: ImmutableMappable { let id: String let name: String init(map: Map) throws { self.id = try map.value("id") self.name = try map.value("name") } }
let result = try Mapper<MyModel>().map(JSONObject: json)
I exepected something like:
MyModel(object: ItemsExtractor<SomeObject>) // with mapped fields
MyModel(object: nil) // mapping doesn't happen even though the key is presented
If I use non-optional type of object in MyModel, all works as expected.
Seems like it was fixed in one of updates. Closing the issue.
Say I have the following
Generic model:
My json:
Model:
It doesn't actually matter what SomeObject looks like in this case, but..
Model:
What I did:
What you expected:
I exepected something like:
What you got:
If I use non-optional type of object in MyModel, all works as expected.