-
Type: Task
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
Problem
I'm using toJSON() on my RealmObject's to get serializable state which I can use in Redux.
BSON.ObjectId's appear to be serialized to an Object which when called with toString() returns the hex string of the ID.
However I was expecting to get a String instead, since I would be able to use a string as key in a Map, to allow fast lookups, whereas the Object comparisons don't work for equality when retrieved from different documents.
Solution
I'm not sure if there's an intent behind serializing the BSON.ObjectId as an Object, but it would be great if they could be serialized as strings instead, similar to BSON.ObjectId.toHexString().
Alternatives
Currently I'm overriding toJSON() on my RealmObjects's and manually serializing to string:
toJSON() { const o = super.toJSON() as MyObject; o._id = o._id.toString(); o.category._id = o.category._id.toString(); return o; }
How important is this improvement for you?
I would like to have it but have a workaround
Feature would mainly be used with
Atlas Device Sync