Objectmapper: How to map in Realm List an array of integers from json

Created on 18 Nov 2017  路  5Comments  路  Source: tristanhimmelman/ObjectMapper

Hello and thanks for the support.
I'm quite new to ObjectMapper (and swift too, migrating from objective c)
I have an array of dictionaries I'm mapping using alamo and objectmapper to Realm.
I mapped all the keys, creating also a couple of custom mappers for custom date format to string and string to bool, and everything is ok
Now I have the last objects to map and I cannot find a clue (even aver googling some hours)

My json snippet is

    "average_rating": "0.00",
    "rating_count": 0,
    "related_ids": [
        1154,
        641,
        880,
        551,
        1062
    ],

I tried to create

var related_ids = List<Int64>()

but I didn't find any way to map the array to Realm list.
Any suggestion? I tried some of the transformers you find in gist related to objectmodel but the understaing is far from my current skill :(

Thanks!

Most helpful comment

The List is introduced in realm 3.0.x. Before that I had to create an IntObject as a realm Object and do some tricky mapping. Now upgrading to 3.0.x, the List is cleaner, but I have issue to do the mapping with ObjectMapper. Anyone can help?

All 5 comments

Any luck to solve your problem. I am facing same problem. How to map the array?
coordinates = (
"76.2710833",
"10.8505159"
);

Any help?

The List is introduced in realm 3.0.x. Before that I had to create an IntObject as a realm Object and do some tricky mapping. Now upgrading to 3.0.x, the List is cleaner, but I have issue to do the mapping with ObjectMapper. Anyone can help?

Any update on this? List of Ints is introduced but still not working with ObjectMapper

It works for List < Int >

func mapping(map: Map)  {
     related_ids <- (map["related_ids"], RealmTypeCastTransform())
}

from https://github.com/APUtils/ObjectMapperAdditions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amg1976 picture amg1976  路  3Comments

AashishSapkota picture AashishSapkota  路  3Comments

maksTheAwesome picture maksTheAwesome  路  4Comments

YunyueLin picture YunyueLin  路  3Comments

borut-t picture borut-t  路  4Comments