Showing error while inserting User in room database

Digvijay :

I am making an app where I am using room as a database cache and fetching data from the server using retrofit2 and saving it in room database but after fetching from server data is unable to insert in room database.

Here is an exception it is showing: enter image description here

This is my pojo class below:

@Entity(tableName = "Users")
public class User {

@NonNull
@PrimaryKey
@SerializedName("_id")
private String _id;

@ColumnInfo(name = "name")
@SerializedName("name")
@Expose
private String name;

@ColumnInfo(name = "age")
@SerializedName("age")
@Expose
private String age;

public User(){}

public User(@NonNull String _id,String name, String age) {
    this._id = _id;
    this.name = name;
    this.age = age;
}

@NonNull
public String get_id() {
    return _id;
}

public void set_id(@NonNull String _id) {
    this._id = _id;
}

public String getName() {
    return name;
}

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

public String getAge() {
    return age;
}

public void setAge(String age) {
    this.age = age;
}
}

JSON Response

[
{
    "id": "5cf68fe7b439470017236249",
    "name": "Rhea",
    "age": "2"
},
{
    "id": "5d09006696a8470cbc7c34a2",
    "name": "Don",
    "age": "10"
},
{
    "id": "5d092d9858af5d22a80858bf",
    "name": "Roman",
    "age": "30"
},
{
    "id": "5d09e9976f3bad18b8fa54a0",
    "name": "Roman",
    "age": "30"
},
{
    "id": "5d09ea2ac127bd07b4b64f6f",
    "name": "Roman",
    "age": "30"
}
]

Someone please let me know what is happening wrong. Any hep would be appreciated.

akshay_shahane :
chnage 

@NonNull
@PrimaryKey
@SerializedName("_id") // key does not match with response key
private String _id;


to 


@NonNull
@PrimaryKey
@SerializedName("id")
private String _id;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=127777&siteId=1