Smuggler
[DEPRECATED] The easiest way to make your data classes Parcelable.
Install / Use
/learn @joomcode/SmugglerREADME
[DEPRECATED]
Please note the library is deprecated now. Consider using @Parcelize instead which is now an official to generate Parcelable implementation.
Smuggler
Makes your data classes Parcelable. Just add AutoParcelable to the class declaration. That's all. No methods need to be implemented.
data class User(
val uuid: String,
val firstName: String,
val lastName: String
) : AutoParcelable
data class Message(
val uuid: String,
val text: String,
val sender: User,
val timestamp: Long,
val seen: Boolean
) : AutoParcelable
data class Chat(
val title: String,
val messages: List<Message>,
val participants: List<User>
) : AutoParcelable
Kotlin objects are supported as well:
interface Command : AutoParcelable
object LoginCommand : Command
object LogoutCommand : Command
object MenuCommand : Command
data class ProductCommand(val id: String) : Command
data class CategoryCommand(val id: String) : Command
Project Setup
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
classpath "com.android.tools.build:gradle:4.2.1"
classpath "com.joom.smuggler:smuggler-plugin:1.1.8"
}
}
repositories {
mavenCentral()
}
apply plugin: "com.android.application"
apply plugin: "com.joom.smuggler"
Some important notes:
- Smuggler plugin must be applied after android plugin.
- In case you have a mutli-module project and want to use
AutoParceable, you have to addsmuggler-pluginto each module.
Supported types
- Primitive types:
boolean,byte,char,double,float,int,long,short - Boxed types:
Boolean,Byte,Char,Double,Float,Int,Long,Short - Other types:
String,Bundle,SparseBooleanArray,Date,SparseArray - All
Parcelablesubclasses - All
Enumsubclasses - All
Serializablesubclasses Arraysof any supported type, including primitive arrays and multidimensional arrays like:Array<Array<Array<User>>Sets,ListsandMapsof any supported type, including primitive types and complex types like:Map<List<Message>, List<Array<Set<User>>>
Custom types
-
Serialization and deserialization of custom types are supported via
TypeAdapter's:object BigIntegerTypeAdapter : TypeAdapter<BigInteger> { override fun fromParcel(parcel: Parcel): BigInteger { return BigInteger(parcel.createByteArray()) } override fun toParcel(value: BigInteger, parcel: Parcel, flags: Int) { parcel.writeByteArray(value.toByteArray()) } } -
Project-level
TypeAdaptercan be registered using@GlobalAdapterannotation:@GlobalAdapter object BigIntegerTypeAdapter : TypeAdapter<BigInteger> { ... } -
Class-level
TypeAdaptercan be registered using@LocalAdapterannotation:@LocalAdapter(BigIntegerTypeAdapter::class, CalendarTypeAdapter::class) data class Local( val integer: BigInteger, val calendar: Calendar ) : AutoParcelable -
Defining
TypeAdapterfor a particular type automatically allows to use this type withLists,Maps,SetsandArrays:data class BigIntegerExample( val single: BigInteger, val array: Array<BigInteger>, val multidimensional: Array<Array<BigInteger>>, val list: List<BigInteger>, val set: Set<BigInteger>, val map: Map<String, BigInteger>, val complex: Map<Set<BigInteger>, Array<List<BigInteger>>> ) : AutoParcelable -
Custom
TypeAdaptercan be defined both asclassorobject -
TypeAdapterdefined asclassmust have a public no-args constructor
How does it work?
Smuggler doesn't use reflection so you don't have to worry about its performance. It isn't an annotation proccessor so you don't have to deal with kapt bugs. Instead, Smuggler built on top of transform api and works by proccessing your compiled bytecode and patching classes that implement AutoParcelable interface.
Known limitations
- Only data classes and kotlin objects are supported
- Data classes with type parameters aren't supported at the moment
- Lists, Maps and Arrays with bounded type parameters aren't supported at the moment
- The library doesn't work nicely with JVM tests at the moment #12
What does "Smuggler" mean?
A smuggler was an individual who dealt with the secret exchanged shipment of goods to block restrictions or tax fees. The items shipped were often considered contraband, and highly illegal. Notable smugglers included Han Solo, Chewbacca, and Lando Calrissian. © http://starwars.wikia.com
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
