Realm-java: Realm copyToRealm and copyOrUpdate not updating fields on "ObjectRealmProxy"

Created on 15 Feb 2018  Â·  2Comments  Â·  Source: realm/realm-java

Goal

Download data, parse it and replace local data

Expected Results

Realm Delete all should delete all objects from realm and new set of objects should be replaced

Actual Results

The "Post" object is parsed correctly and once it is send to realm to copy it is not copied as it should, as you can see on the image the Post= proxy object has the correct values set, but the actual values on the RealmProxy object are nulls or empty or set to default values.

image

E.g. full stack trace with exception
No exception shown

Steps & Code to Reproduce

final RealmResults results = realm.where(Post.class).findAll();
if (response.getPostList() != null && response.getPostList().size() > 0) {
realm.beginTransaction();
results.deleteAllFromRealm();
//response has post list with correct parsed objects
//results is empty
realm.copyToRealm(response.getPostList());
//results has the values returned from the server but with null values
realm.commitTransaction();

Describe your current debugging efforts.

I followed the code and the "copyToSource" object used to copy the values have null values in all the fields, there is not exception on the code
On RealmProxy object method copyOrUpdate()
RealmObjectProxy cachedRealmObject=null;
then Copy method is executed, on copy method realmObjectSource includes all the correct data in all fields, but once it is accessed on realmGet it returns default value
image

Code Sample

public class Post extends RealmObject implements IModel<Integer> {

    @PrimaryKey
    @SerializedName("Id")
    private int id;
    @SerializedName("UserId")
    private int userId;
    @SerializedName("GroupId")
    private int groupId;
@Override
    public Integer getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }
} 

Version of Realm and tooling

Realm version(s): 4.3

Realm sync feature enabled: yes/no

Android Studio version: 3.0.1

Which Android version and device: it is happening with multiple devices
Nexus 6 and version 27

Most helpful comment

https://realm.io/docs/java/latest/#android-studio-debugging-android-studio-debugging

All 2 comments

https://realm.io/docs/java/latest/#android-studio-debugging-android-studio-debugging

(it's because managed RealmObject property access is lazy-loaded)

Was this page helpful?
0 / 5 - 0 ratings