Using IEmbeddedObject as RealmValue

Hi there,

I have data design question, i have a json object gathered from a server, looking like this:

{ 
  "objects": [
    {
      "id": "some_id",
      "custom_data": { "some_key": 1, "other_string": "a" }
    },
    {
      "id": "totally_different_id",
      "custom_data": { "totally_different_object": 942, "stuff": { "a" : 5 } }
    }
  ]
}

So I want to mirror this layout to a realm object like this:

public partial class ServerObjects: IRealmObject {
    [MapTo("objects")] public IList<ServerItem> Objects;
}

public partial class ServerItem: IEmbeddedObject {
    [MapTo("id")] public string Id {get; set;}
    [MapTo("custom_data")] RealmValue CustomData;  //?????????
}

public partial class SomeIdCustomData: IEmbeddedObject {
///some fields
}

public partial class TotallyDifferentIdCustomData: IEmbeddedObject {
///some fields
}

Somehow I need to map different custom data to their corresponding classes. I can have a mapping from id to their data type, so i can parse json according to that, but after putting them in a realm value, it says IEmbeddedObjects are not supported by RealmValue yet error. If I make custom data classes IRealmObjects then they have their own objects dangling around the db. I want them to be embedded.

What is the best approach to handle these kind of problems? I can change the design completely.

Thanks.

Embedded objects cannot exist on their own. They are not managed objects, and do not have an official object id (although it can have one, it’s just not used by Realm).

I am not sure it’s clear what you want embedded - embedded objects are often part of a List, although they could be defined as a single object property as well.

Can you clarify the question?