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?

3
  • 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. Commented Jan 26, 2022 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? Commented Jan 26, 2022 at 11:34
  • I'm saying that if you want to completely "free" you code from Android then you can't use Parcelable. Commented Jan 26, 2022 at 16:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.