问题描述
我在我的应用程序中使用Retrofit和JSON的GSON转换器.没有Internet连接时,我想使用数据库.我决定使用糖ORM. 但是我得到了一个IllegalArgumentException.
java.lang.illegalargumentException:无法为类创建转换器
这是我的对象
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
推荐答案
问题是,使用糖时,您不能在类中使用id的变量,因为默认情况下它使用了自己的内部ID.尝试重命名为userId或类似的东西.
其他推荐答案
只需在 threstient 语句整数 type.
@SerializedName("id") @Expose private transient Integer id;
那么,如果您有 getID 和 setID 方法,则应删除它们.
玩得开心!
问题描述
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
推荐答案
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.
其他推荐答案
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!