paperparcel 0,0 travis-ci

Android Parcelable boilerplate annotation processor

PaperParcel

Build Status

http://blog.bradcampbell.nz/introducing-paperparcel/

Overview

PaperParcel is an annotation processor that automatically generates type-safe Parcelable boilerplate code for Kotlin and Java. PaperParcel supports Kotlin Data Classes, Google's AutoValue via an AutoValue Extension, or just regular Java bean objects (for lack of a better word).

Annotated data classes can contain any type that would normally be able to be parcelled. This includes all the basic Kotlin/Java types, Lists, Maps, Sets, Arrays, SparseArrays, Kotlin object declarations, and many more (the full list can be found here).

PaperParcel is 100% generated code, no reflection or byte-code manipulation is involved. You can see all the generated classes yourself by viewing the auto-generated PaperParcelMapping class after a build.

Usage

All documentation can be found in the wiki:

Type Adapters

Occasionally when using PaperParcel you might find the need to parcel an unknown type, or modify how an object is read/written to a Parcel. TypeAdapters allow you to do this.

A good example of when you might want this functionality is with java.util.Date objects. By default, PaperParcel will recognise Date as Serializable, and use Serialization as the Parcel reading/writing mechanism. Serialization is slow, so you might want to write a custom TypeAdapter for a Date object.

Defining TypeAdapters for a particular type automatically allows the use of this type with any container type, e.g. a TypeAdapter for Date will apply to the Date elements in List<Map<String, Date>>.

For information on how to define and use TypeAdapters, see the Type Adapters wiki page.

Limitations

Classes with type parameters cannot be annotated with @PaperParcel

E.g.: you can't do the following:

@PaperParcel 
data class BadExample<T>(
  val child: T
) 

An issue has been raised for this here.

Download (Kotlin)

kapt {
    generateStubs = true
}
repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.grandstaish.paperparcel:paperparcel:1.0.0'
    compile 'com.github.grandstaish.paperparcel:paperparcel-kotlin:1.0.0'
    kapt 'com.github.grandstaish.paperparcel:compiler:1.0.0'
}

Download (AutoValue)

repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
}
dependencies {
    provided 'com.google.auto.value:auto-value:1.2'
    apt 'com.google.auto.value:auto-value:1.2'
    compile 'com.github.grandstaish.paperparcel:paperparcel:1.0.0'
    apt 'com.github.grandstaish.paperparcel:compiler:1.0.0'
}

Note that the android-apt plugin must be applied.

Download (Java)

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.grandstaish.paperparcel:paperparcel:1.0.0'
    compile 'com.github.grandstaish.paperparcel:paperparcel-java7:1.0.0'
    apt 'com.github.grandstaish.paperparcel:compiler:1.0.0'
}

Note that the android-apt plugin must be applied.

Proguard

In addition to the default Android rules set by proguard-android.txt in the SDK, add the following rules to your project proguard file:

-dontwarn org.jetbrains.annotations.**
-keepclassmembers class nz.bradcampbell.paperparcel.PaperParcelMapping {
  static ** FROM_ORIGINAL;
  static ** FROM_PARCELABLE;
}

Contributing

I would love contributions to this project if you think of anything you would like to see in the project or find any bugs. If you would like to contribute, first raise a GitHub issue so we can discuss the change you want to make.

The best way to contribute is to fork the project on github then send me a pull request via github.

If you create your own fork, it might help to enable rebase by default when you pull by executing git config --global pull.rebase true. This will avoid your local repo having too many merge commits which will help keep your pull request simple and easy to apply.

License

Copyright 2015 Bradley Campbell.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Related Repositories

kotgo

kotgo

...

awesome-kotlin

awesome-kotlin

A curated list of awesome Kotlin related stuff Inspired by awesome-java. ...

Kotlin-Android-Boilerplate

Kotlin-Android-Boilerplate

Kotlin Android Boilerplate project with MVP architecture using RxJava, Dagger 2, ...

kotlin-anko-demo

kotlin-anko-demo

Example How to use Kotlin & Anko for Android development https://vsouhrada.githu ...

awesome-kotlin

awesome-kotlin

A curated list of awesome Kotlin related stuff Inspired by awesome-java. ...


Top Contributors

grandstaish edenman johnjohndoe

Releases

-   1.0.0 zip tar
-   1.0.0-rc5 zip tar
-   1.0.0-rc4 zip tar
-   1.0.0-rc3 zip tar
-   1.0.0-rc2 zip tar
-   1.0.0-rc1 zip tar
-   1.0.0-beta8 zip tar
-   1.0.0-beta7 zip tar
-   1.0.0-beta6 zip tar
-   1.0.0-beta5 zip tar
-   1.0.0-beta4 zip tar
-   1.0.0-beta3 zip tar
-   1.0.0-beta2 zip tar
-   1.0.0-beta1 zip tar
-   0.9.9 zip tar
-   0.9.8 zip tar
-   0.9.7 zip tar
-   0.9.6 zip tar
-   0.9.5 zip tar