Search in sources :

Example 1 with PrimaryKeyAsObjectId

use of io.realm.entities.PrimaryKeyAsObjectId in project realm-java by realm.

the class RealmJsonTests method createOrUpdateObjectFromJson_objectIdPK.

@Test
public void createOrUpdateObjectFromJson_objectIdPK() throws JSONException {
    String stringId = "789ABCDEF0123456789ABCDE";
    JSONObject jsonObject = new JSONObject("{\"id\": \"" + stringId + "\", \"name\": \"bar\"}");
    realm.beginTransaction();
    realm.createOrUpdateObjectFromJson(PrimaryKeyAsObjectId.class, jsonObject);
    realm.commitTransaction();
    RealmResults<PrimaryKeyAsObjectId> owners = realm.where(PrimaryKeyAsObjectId.class).findAll();
    assertEquals(1, owners.size());
    assertEquals(new ObjectId(stringId), owners.get(0).getId());
    assertEquals("bar", owners.get(0).getName());
}
Also used : JSONObject(org.json.JSONObject) PrimaryKeyAsObjectId(io.realm.entities.PrimaryKeyAsObjectId) ObjectId(org.bson.types.ObjectId) PrimaryKeyAsObjectId(io.realm.entities.PrimaryKeyAsObjectId) Test(org.junit.Test)

Aggregations

PrimaryKeyAsObjectId (io.realm.entities.PrimaryKeyAsObjectId)1 ObjectId (org.bson.types.ObjectId)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1