I'm using working on a project in the CLEAN architecture where the project is broken into the "Presentation", "Domain" and "Data" modules, where the Domain module hosts the "Entities" that are basically the data models specific to this project. An example of this architecture is here.
Unlike the other two module, "Domain" is a pure Java library module, which is great for clarity and testing as it doesn't have the Android overhead, however it also means I'm now not able to use libraries like "Parceler" to which is very Android specific. Is there a way around this?
Parceler allows you to configure beans outside of the given module to generate a wrapping Parcelable via the @ParcelClass
annotation. This means you can configure the given bean as a @Parcel
outside of the Data layer, and in the presentation layer (or wherever else you want). See http://parceler.org/#classes_without_java_source for specifics.
The org.parceler:parceler-api module is also pure Java, it has no dependencies on the Android api. Therefore you should be free to annotate your Data module without violating the CLEAN archetecture you're seeking. The annotation compiler portion (org.parceler:parceler) of the library, however, does rely on the Android API, so you'll need to run it in the android-specific module. This leaves you with the follow:
Include the parceler-api library in your Data module and annotate your Data layer beans (@Transient
, @ParcelProperty
, etc). If you don't need any specific configuration, you can avoid including the parceler-api as a dependency.
Add the parceler and parceler-api libraries to your Android-specific module (Presentation?).
Add a @ParcelClass
annotation with each class from your data module you want to be an @Parcel
to an arbitrary class (Application
?). This will direct Parceler to generate a Parcelable
for each class identified within the @ParcelClass
parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With