Objectmapper: generic array type

Created on 5 Jan 2017  路  4Comments  路  Source: tristanhimmelman/ObjectMapper

I want to write the follow code, the T is Array<User>, and User is a Mappable class. but the objectMapper can not do this for me. please give me a favor
responseModel = Mapper<ResponseModel<T>>().map(JSON: value as! [String: Any])

Most helpful comment

Hi I'm having the same problem now and the language I use is Swift 4

Is there a shorter way to do this without creating more boilerplate?

All 4 comments

Yeah, I know it is totally inconvenient, because if you want ot map directly an array of mappable object - you have to use explicitly a different function.
This is because Array of Mappable is not Mappable by itself. I believe this inconvenience will be fixed in swift 4.

If u understand you correctly - you want to have a wrapper object for all of your responses. Where T is its generic value. If that is the case, you can do the following:
As you are having ResponseModel<T> , you can define ResponseArray<T> that will define its result to be [T].
This way - you will only have to explicitly use either ResponseModel or ResponseArray, depending on your result.

Thanks @KoCMoHaBTa, that's correct.

Hi I'm having the same problem now and the language I use is Swift 4

Is there a shorter way to do this without creating more boilerplate?

I have same problem too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maksTheAwesome picture maksTheAwesome  路  4Comments

YunyueLin picture YunyueLin  路  3Comments

Dbigshooter picture Dbigshooter  路  4Comments

borut-t picture borut-t  路  4Comments

danyalaytekin picture danyalaytekin  路  4Comments