I have a
JSON
{
"name": "name",
...
...
"profile": {
"id": 987,
"first_name": "first name"
...
...
}
}
JSON
Realm
realm.createObjectFromJson(Class clazz, String string)
RealmObject
"profile"
0
null
realm.beginTransaction()
realm.commitTransaction()
'io.realm:realm-android:0.80.1'
public class SomeClass extends RealmObject {
private String name;
private Profile profile;
public Profile getProfile() {
return profile;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
}
public class Profile extends RealmObject {
private String firstName;
private String lastName;
private String birthdate;
private boolean newsLetter;
private boolean push;
private int userId;
private Date lastUpdate;
private RealmList<RealmAddress> addresses;
private RealmList<RealmGender> genders;
}
Your JSON names doesn't match your child object field names which is why you don't see any data. Your profile
name matches the field in SomeClass
, which means the object gets created (with default values), but as none of the fields match in Profile
, none of them are set.
firstName != first_name
userId != id
If you want to have separate names in your JSON and the Java models you should use something like GSON (http://realm.io/docs/java/#gson) as that is not yet supported by Realm directly.