Hi,
I’m struggling to properly serialize my model that includes a realmList of embedded objects.
Here is my data model:
@Serializable
class InventoryItem: EmbeddedRealmObject {
var upc: String = ""
var quantity: Long = 0
var quantityType: String = ""
var retail: Long = 0
var cost: Long = 0
var totalRetail: Long = 0
var totalCost: Long = 0
}
@Serializable
class InventoryBatch: RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var dateTime: RealmInstant = RealmInstant.now()
@Serializable(RealmListKSerializer::class)
var inventoryItems: RealmList<InventoryItem> = realmListOf()
var inventoryType: String = ""
var notes: String? = null
var status: String? = null
var store: String = ""
var tenantId: String = ""
var transferStore: String? = null
var user: String = ""
}
My understanding from the Docs is that I should just need to add the @Serializable tag annotation to the class and register the serializer for the property. However when I query inventory batches I get the following error:
kotlinx.serialization.SerializationException: Class 'RealmResultsImpl' is not registered for polymorphic serialization in the scope of 'RealmResults'.
To be registered automatically, class 'RealmResultsImpl' has to be '@Serializable', and the base class 'RealmResults' has to be sealed and '@Serializable'.
Here is my query:
var inventoryBatch: RealmResults<InventoryBatch> = inventoryRealm.query<InventoryBatch>("status == $0", "open").find()
What am I doing wrong here?