Is it possible to use other variable names in Realm?

时间:2016-05-17 11:14:13

标签: android realm

I would like to parse a JSON object and map it to a RealmObject directly using the method createObjectFromJson. My JSON is looking like that:

"data": {
  "default": "a string"
}

So I make a RealmObject class like this

public class Data extends RealmObject{
  private String default;
  // GETTERS AND SETTERS
}

So I can call the method

realm.createObjectFromJson(Data.class, json);

Obviously the problem here is that I cannot use the keyword default to name my variable. Is there any way to annotate my variable in Realm to use an alias ? I'm aware that I can modify my input JSON but the aim is not to do it so I can have a generic method to map my JSON to a RealmObject.

1 个答案:

答案 0 :(得分:0)

Realm不支持重命名变量,但是像GSON和Jackson那样的JSON库。您应该查看这些内容,然后使用copyToRealmcopyToRealmOrUpdate代替createObjectFromJson