Is this normal to set a nullable properties in Ent...
# android
k
Is this normal to set a nullable properties in Entity and Model class? Should we use non null "val" instead?
Copy code
data class DataInputEntity(
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "id") val id: Int,
    @ColumnInfo(name = "weight") var weight: Float? = null,
    @ColumnInfo(name = "body_fat") val bodyFat: Float? = null,
    @ColumnInfo(name = "stamp") val stamp: String,
    @ColumnInfo(name = "note") val note: String,
    @ColumnInfo(name = "date") val date: Long,
    @ColumnInfo(name = "unit") val weightUnit: Int = TypeUnitWeight.KG.value
)
a
Nullability will just depend on how you want to model your data. Regardless, I would suggest always having all properties as
val
and use the
copy
function to perform changes.
👍 1
a
Depends on how much you trust your API. If you require nullables, it would be better to make them
val
and convert your network entity into a non-nullable entity for the other layers of your app, preferably with some checks during conversion.
👍 1
k
Thank you guys, I get the idea now