use of io.realm.exceptions.RealmException in project realm-java by realm.
the class LinkingObjectsManagedTests method json_updateObject.
// Fields annotated with @LinkingObjects should not be affected by JSON updates
@Test
public void json_updateObject() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.setFieldObject(child);
realm.commitTransaction();
RealmResults<AllJavaTypes> parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
realm.beginTransaction();
try {
realm.createOrUpdateAllFromJson(AllJavaTypes.class, "[{ \"fieldId\" : 1, \"objectParents\" : null }]");
} catch (RealmException e) {
fail("Failed loading JSON" + e);
}
realm.commitTransaction();
parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
}
Aggregations