tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.14k stars 1.03k forks source link

How to map in Realm List an array of integers from json #919

Closed appfabtech closed 4 years ago

appfabtech commented 6 years ago

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!

Shiju86 commented 6 years ago

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

Any help?

qgliu commented 6 years ago

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?

GregoryGevorkyan commented 6 years ago

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

bptstmlgt commented 6 years ago

Solved this issue with: https://github.com/APUtils/ObjectMapperAdditions

vasadulin commented 5 years ago

It works for List < Int >

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

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