createOrUpdateFromJson also updates fields not set
If you update a existing RealmObject using Realm.createOrUpdateFromJson() it correctly creates default values for fields not set, however if a existing RealmObject is found the expected behavior would be to only override the fields actually set, eg
public class Data extends RealmObject {
@PrimaryKey
private int id;
private boolean bool;
private String str;
...
}
// From empty database
realm.beginTransaction();
Data obj = realm.createOrUpdateFromJson(Data.class, "{ "id":1, "str": "foo" });
obj.setBool(true);
realm.commitTransaction();
realm.beginTransaction();
obj = realm.createOrUpdateFromJson(Data.class, "{ "id":1, "str": "foo" })
realm.commitTransaction();
obj.isBool() == false; // unexpected, it should maintain its value unless specifically set.
This is also the case when using: copyToRealmOrUpdate(E extends RealmObject)
Actually, when using copyToRealmOrUpdate, you have an existing object. It is impossible to tell the difference between an value not set and it's default value, so there it should override all properties. This is not the case for JSON objects where the field definition might miss altogether.
Point taken :+1:
.