3

I am getting my objects from the web and directly inserting them into ROOM DATABASE

@Entity(tableName = Constants.TABLE_OBJECT_ICONS)
public class ObjectClass {

    @PrimaryKey()
    @SerializedName("id")
    @ColumnInfo(name = Constants.KEY_OBJECT_ID)
    @Expose
    private Integer id;

    @SerializedName("controlUnit")
    @ColumnInfo(name = Constants.KEY_CONTROL_UNIT)
    @Expose
    private String controlUnit;

    @SerializedName("isStack")
    @ColumnInfo(name = Constants.IS_STACK)
    @Expose
    private Boolean isStack;

    public Boolean getStack() {
        return isStack;
    }

    public void setStack(Boolean stack) {
        isStack = stack;
    }

    public Integer getId() {
        return id;
    }

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

    public String getControlUnit() {
        return controlUnit;
    }

    public void setControlUnit(String controlUnit) {
        this.controlUnit = controlUnit;
    }

}

Now the problem is, I am inserting Boolen datatype into DB and room is mapping it into 0 and 1, but when I'm trying to fetch data my getStack() methods returns null

UPDATE

Here is the Dao

@Dao
public interface ObjectDao {

    @Insert
    void insertObject(ObjectClass objectClass);

    @Query("DELETE FROM object_icons")
    void deleteAllObjects();

    @Query("SELECT * FROM object_icons WHERE object_id=:id AND site_id=:siteId")
    Single<ObjectClass> getObjectById(String id, String siteId);

    @Query("SELECT object_name FROM object_icons WHERE object_id=:id AND site_id=:siteId")
    String getObjectNameById(String id, String siteId);

    @Query("SELECT * FROM object_icons WHERE object_keyword=:key AND site_id=:siteId")
    ObjectClass getObjectByKey(String key, String siteId);

    @Query("SELECT * FROM object_icons WHERE site_id=:siteId")
    Single<List<ObjectClass>> getObjectIconsList(String siteId);

}

and after taking the Database I opened it into SQLite Online following is the structure of database.

enter image description here

Kanwarpreet Singh
  • 2,037
  • 1
  • 13
  • 28

1 Answers1

0

Referring to this answer Room should convert 1 to true when you're reading your object. Also it seems that if you're migrating from Sqlite to Room you might have some issue with Boolean and Integer type, I don't know if this is your situation but here is a link in case: room migration using existing boolean column types

Biscuit
  • 4,840
  • 4
  • 26
  • 54