realm/realm-java — pull request #489 by cmelchior (2014-10-21 19:43:26+00:00)
Title: JSON Import API

API methods :
```
Realm.createObjectFromJson(Class realmObject, JSONObject json)
Realm.createAllFromJson(Class realmObject, JSONArray json)

// Uses JsonReader for stream parsing. Only for API 11+
Realm.createObjectFromJson(Class realmObject, InputStream json);
Realm.createAllFromJson(Class realmObject, InputStream json);
```

A few comments:

- Import using InputStream only works for API 11+. Methods are annotated as such.

- JSON property names need to match java variabel names.

- Import API does not work in standard Java. JSON is only supported from Java 7, and with a different API.

- If import fails, everything up to that point is put in the database (if Realm.commitTransaction() is called). We need a Realm.rollback() to change this behavior.

- functions like createOrUpdateFromJson() would be natural extensions but awaits primary key support.