Need help with smuggler?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

joomcode
203 Stars 6 Forks MIT License 513 Commits 4 Opened issues

Description

[DEPRECATED] The easiest way to make your data classes Parcelable.

Services available

!
?

Need anything else?

Contributors list

[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, val participants: List ) : AutoParcelable

Kotlin objects are supported as well: ```kotlin 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()
    jcenter()
  }

dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71" classpath "com.android.tools.build:gradle:3.5.3" classpath "com.joom.smuggler:smuggler-plugin:1.0.5" } }

repositories { mavenCentral() jcenter() }

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 add
smuggler-plugin
to 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
    Parcelable
    subclasses
  • All
    Enum
    subclasses
  • All
    Serializable
    subclasses
  • Arrays
    of any supported type, including primitive arrays and multidimensional arrays like:
    Array>
  • Sets
    ,
    Lists
    and
    Maps
    of any supported type, including primitive types and complex types like:
    Map, List>>

Custom types

  • Serialization and deserialization of custom types are supported via

    TypeAdapter
    's: ```kotlin object BigIntegerTypeAdapter : TypeAdapter { 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

    TypeAdapter
    can be registered using
    @GlobalAdapter
    annotation:
  @GlobalAdapter
  object BigIntegerTypeAdapter : TypeAdapter {
    ...
  }
  • Class-level
    TypeAdapter
    can be registered using
    @LocalAdapter
    annotation:
  @LocalAdapter(BigIntegerTypeAdapter::class, CalendarTypeAdapter::class)
  data class Local(
    val integer: BigInteger,
    val calendar: Calendar
  ) : AutoParcelable
  • Defining
    TypeAdapter
    for a particular type automatically allows to use this type with
    Lists
    ,
    Maps
    ,
    Sets
    and
    Arrays
    :
  data class BigIntegerExample(
    val single: BigInteger,
    val array: Array,
    val multidimensional: Array>,
    val list: List,
    val set: Set,
    val map: Map,
    val complex: Map, Array>>
  ) : AutoParcelable
  • Custom
    TypeAdapter
    can be defined both as
    class
    or
    object
  • TypeAdapter
    defined as
    class
    must 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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.