Closed ghost closed 5 years ago
Hello @asadhyt
Probably you should declare var data
as [T]?
.
I think this issue is duplicated with #1043
@PH9 - I'm pretty sure this issue is separate since it both doesn't involve Swift 5 and because I am still experiencing it after upgrading to ObjectMapper 3.5.x.
This issue as I understand it here is that ObjectMapper understands a slew of types that don't conform to the Mappable
protocol - both "Nesting" objects like arrays and dictionaries and "Primative" values like strings and booleans. However, because they don't conform to the Mappable
protocol, @asadhyt can't pass them as the generic argument to his class and, even if he could, the Mapper
generic format doesn't successfully unwrap objects that aren't Mappable
. I haven't dug into the code yet, but I think the solution is either going to be to make those types all Mappable
or to correct the Mapper so that it can understand either Mappable
types or these raw mappable types.
For now, @asadhyt, I'm working around this in my app in the following way:
BaseResponse
class is now just a protocol that defines an expectation of the fields a response will have. In your case, status
, message
, and data
.ResponseWithObject<T: Mappable>
and ResponseWithArrayOfObject<T: Mappable>
class, each of which looks like your class and conform to BaseResponse
, except the Array variant follows @RomanPodymov's suggestion of declaring data to be of type [T]?
post
method of Response: BaseResponse
that declares which response type is expected.Thanks everyone.
@zackdotcomputer thanks for sharing your idea.I noticed that this PR is closed at several years ago.But Im a new swifter.Did you find out an universal way or a different way to resolve this problem now?Thank you
@steve7688 I wound up moving away from this package towards using Decodable
wow that's great.maybe I should learn how to integrate Decodable in my project
i want to map my response for api calls. I have written a generic method to handle all api call. Below is method
BaseResponse:
Now usually i am using above method like this
This works fine when response json have keys but now i have to handle this json which dont have keys inside 'data'
This is json i wanna parse:
I'm having trouble creating mappable class for above json since it don't have keys inside data. Please help! thanks!