Objectmapper: Alternative keys for the same property

Created on 1 Nov 2017  路  2Comments  路  Source: tristanhimmelman/ObjectMapper

Your JSON dictionary:

{
    "user_name" : "John Doe"
}

```json
{
"userName" : "John Doe"
}

### Your model:

```swift
class User :  Mappable{

    var userName : String?

    func mapping(map: Map)
    {
        userName <- map["userName"]

    }
}

Is there any way to let ObjectMapper support multiple keys for the same property in the Model ?
This is a good way to support APIs from different enviroments

Most helpful comment

ObjectMapper does not provide a mechanism for handling this situation. You can easily check if a value was successfully mapped in the mapping function though.

userName <- map["userName"]
if userName == nil {
    username <- map["user_name"]
}

All 2 comments

same question

ObjectMapper does not provide a mechanism for handling this situation. You can easily check if a value was successfully mapped in the mapping function though.

userName <- map["userName"]
if userName == nil {
    username <- map["user_name"]
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nearspears picture nearspears  路  4Comments

delbyze picture delbyze  路  3Comments

borut-t picture borut-t  路  4Comments

maksTheAwesome picture maksTheAwesome  路  4Comments

quetool picture quetool  路  3Comments