2

I am using retrofit in my app and Gson convertor for JSON. I would like to use database when there is not internet connection. I decided to use Sugar ORM. but I get an IllegalArgumentException.

java.lang.IllegalArgumentException: Unable to create converter for class

here is my object

public class User extends SugarRecord implements Parcelable {

    @SerializedName("id")
    @Expose
    private Integer id;
    @SerializedName("email")
    @Expose
    private String email;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("lastname")
    @Expose
    private String lastname;
    @SerializedName("properties")
    @Expose @Ignore
    private List<Object> properties = new ArrayList<>();
    @SerializedName("rights")
    @Expose @Ignore
    private String rights;
    @SerializedName("photo")
    @Expose
    private String photo;
    @SerializedName("favorites")
    @Expose @Ignore
    private List<PointsOnMap> favorites = new ArrayList<>();
    @SerializedName("token")
    @Expose
    private String token;

    public User() {
    }

    public User(String name, String lastname, String email, String photo, String token) {
        this.name = name;
        this.lastname = lastname;
        this.email = email;
        this.photo = photo;
        this.token = token;
    }
    //getters and setters
Racil Hilan
  • 23,737
  • 12
  • 48
  • 51
Stepan
  • 929
  • 4
  • 21
  • 33

2 Answers2

3

Problem is you can't have a variable named id in your class when using Sugar since by default it uses its own internal ids. Try renaming to userId or something like that.

fhomovc
  • 301
  • 3
  • 15
1

Just use transient statement before Integer type.

    @SerializedName("id")
    @Expose
    private transient Integer id;

Then, if you have getId and setId methods, should delete them.

And have fun!