While PaperParcel 1.x and 2.x have very similar APIs, there has been a several breaking changes (including several APIs having been removed). This guide is intended to help users with the migration process from 1.x to 2.x.
Package Name Change
The package name of the library has changed from nz.bradcampbell.paperparcel
to just paperparcel
.
Additionally, the artifacts are no longer available on jitpack and are instead available on jcenter and mavenCentral under a new group id. See Download for more info.
Wrappers
PaperParcel used to have a concept of Parcelable wrappers. These no longer exist in 2.x. There are several reasons for removing them:
- They require reflection and runtime class lookups, which can be costly on Android (especially when parcelling a lot of model objects at the same time).
Parcelable
is intended to be performant! - They don't play well with other libraries that require
Parcelable
s. Examples include Dart, IcePick, and FragmentArgs. Some of these libraries have APIs for allowing wrapper objects, but it's better practice to just have objects that are actuallyParcelable
instead. - Removing them means having fewer method references.
- There were complications with library projects and multi-module projects.
- Wrappers make it harder to opt out of using a library because the wrapping code is usually scattered around both UI and model classes.
Instead, PaperParcel 2.x just generates the CREATOR
and writeToParcel(...)
implementations for you. Then you can simply make your model objects implement Parcelable
and use/call the generated code from your model.
Here's a list of things you need to do to remove all of the old wrapper-based code:
- Ensure that all of your
@PaperParcel
classes also implementParcelable
. Override the required methods, but leave them blank for now. - If you have references to
PaperParcels
, delete them next. This class no longer exists as it was only used for wrapping and unwrapping types. - If you have references to
TypedParcelable
, you need to delete those too. This interface no longer exists. - If you have references to
PaperParcelable.Creator
, you need to delete those too. This was removed in favour of the newly generatedCREATOR
s that don't rely on wrappers. - Build and then use the generated code in your models as shown in the Usage section of the website.
Type Adapters
The TypeAdapter
API hasn't changed, but the API for adding them has. See Processor Configuration from the website to find out how to add your existing TypeAdapter
s.
While the API is exactly the same, TypeAdapter
s have actually gained some new tricks. See Type Adapters from the website to find out more.
Proguard
You can delete the old rules associated with this library. PaperParcel 2.x doesn't use reflection anymore. If you're opting into the reflection-enhanced API in paperparcel-kotlin
, the rules now ship with the AAR so you don't need to do anything.