Using Realm with Gson
<p>I have <code>json</code> with field <code>_id</code></p>

<pre><code> String json = "{ _id : 1, name : 'Alex', role: 'admin' }"
</code></pre>

<p>In my Realm model I use <code>@SerializedName</code> attribute:</p>

<pre><code>public class User extends RealmObject {

    @SerializedName("_id")  
    @PrimaryKey
    private int id;
    private String name;
    private String comment;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

}  
</code></pre>

<p>If try save the json:</p>

<p><code>realm.createOrUpdateObjectFromJson(User.class, json)</code></p>

<p>field <code>_id</code> can't parsed and in database created record with id = 0</p>

<p>In docs using <code>@SerializedName</code> attribute</p>

<pre><code>  Gson gson = new GsonBuilder()
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class&lt;?&gt; clazz) {
                    return false;
                }
            }).create();


User user = gson.fromJson(json, User.class);
realm.beginTransaction();
realm.copyToRealmOrUpdate(user);
</code></pre>

<p>In this case <code>json = "{ _id : 1, role: 'user' }"</code> just remove user <code>name</code> from database, because default value for String is null.</p>

<p>So, probably I incorrectly using the attribute. How to consider the attribute when dealing with the methods of conservation of json (<code>createOrUpdateObjectFromJson</code>, etc)?</p>