0

I am using object mapper library in swift fro parsing JSON to object and I have a JSON which looks like this:

"_links" :     {
    "category.genres":         {
        "href" : "http://dev.abcd.com/api/v1/categories/series/genres"
    }

}

I am trying to map href to model but I am not able to find any solution here. I tried to do

genreLink <- (map["_links"]["category.genres",nested: false]["genres"],urlTransform)

But it doesn't work, Please guide. Thanks

2 Answers 2

3

Unfortunately, I don't think your situation is supported using the nested keys feature of ObjectMapper. This is because of one keys in the nesting already has a period in it. If it didn't the mapping would look like the following:

genreLink <- (map["_links.category_genre.href"], urlTransform)

Chaining the mappings as you have done above is not supported. To properly map this, I think you will need to create some model classes (that implement Mappable) for Links and Category.genres or change the API response if possible.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the prompt response. I think I will have to go with the model classes since API response is not in my control.
@tristan_him, do you mean genreLink <- (map["_links.category_genre.href"], urlTransform)
0

As per documentation:

When you have nested keys which contain ., you can pass the custom nested key delimiter as follows (#629):

func mapping(map: Map) {
    appName <- map["com.myapp.info->com.myapp.name", delimiter: "->"]
}

Reference: Custom nested key delimiter in mapping

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.