4

I am trying to break my android app into smaller gradle modules (for now data and model modules). I want to keep my model module as a Kotlin library because it will only contains data classes. But some of those data classes are Parcelable. To use Parcelable in model module I will have to convert it to an Android library which I am trying to avoid.

One solution that I can think of is to create another class in app module with the exact same structure as the original class in model module and then write a mapper function from one class to another. But it looks like a lot of boilerplate just to make them Parcelable.

Is there a better way to do so?

Arpit Shukla
  • 9,612
  • 1
  • 14
  • 40
  • Maybe on each model class have a toJSON() method that returns a JSONObject, or a String, and a constructor that excepts JSONObject (or a string)?. This will require a call to toJSON() whenever you want to encode and create an object using the JSON constructor to decode. – gioravered Jan 26 '22 at 10:33
  • @gioravered Are you saying that I shouldn't make it `Parcelable` and instead use the Json string to pass the model between screens? – Arpit Shukla Jan 26 '22 at 11:34
  • I'm saying that if you want to completely "free" you code from Android then you can't use Parcelable. – gioravered Jan 26 '22 at 16:01

0 Answers0