0

To save boilerplate, I thought it would be a cool idea to make my Room Entity a Serializable and pass it around in an Intent - but I had a bad feeling in doing this. Surely enough, this article and this SO post advise against doing so.

Thus I made a Serializable data class, and made it the sole column in the Entity. Is this adequately addressing the concerns, or does this not really solve anything at all? Both classes lie in the same module.

Vehicle.kt

@Entity
data class Vehicle(
    @PrimaryKey val data: VehicleData
)

VehicleData.kt

data class VehicleData(
    val workArea: String,
    val vehicleNumber: String
): Serializable
El Sushiboi
  • 428
  • 7
  • 19
  • "or does this not really solve anything at all?" -- it does not address any of the concerns that I raised in [my answer to the SO question that you linked to](https://stackoverflow.com/a/56058763/115145). I also would not expect that to compile, unless you have a `TypeConverter` that is teaching Room how to store a `VehicleData` in a single column. And, even if you do that, then you basically break your ability to query on each `VehicleData` property (e.g., query for all vehicles in a work area). – CommonsWare Nov 14 '20 at 15:17
  • 1
    So, you would be better off just making `VehicleData` be the `@Entity`. For trivial projects, particularly solo-developer projects, you can probably get away with having your Room entities be `Serializable` or `Parcelable` and pass them around. I would not recommend that for any serious project, for the reasons that I outlined in that answer. – CommonsWare Nov 14 '20 at 15:19

0 Answers0