Dhiraj Gupta Dhiraj Gupta - 1 year ago 94
JSON Question

Realm createOrUpdateAllFromJson to create RealmModel objects without persisting?

I'm using realm Java in my in-development Android app quite happily. I receive

arrays from the server API, and realm dutifully ingests them through the convenient
on the main realm instance object.

The typical flow for this looks like:

// get API results into JSONArray jsonObjArrs variable

However, I've now run into a situation where I would like to create a temporary, in-memory array of the same
objects without actually saving them to Realm, because I want to throw these away as soon as the specific use case is done. It looks to me like
and its sibling methods are only available on the main realm instance object.

Is there any way to harness this convenient
to object model creator, or do I have to write an alternate implementation with manual / automated JSON parsing?

Answer Source

If you want in-memory objects from a JSON structure, your should look at a standard JSON parser like GSON, Jackson or Moshi. Realm does not have any inbuilt way of doing this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download