Android Parcelable support for the Kotlinx Serialization library.

Last update: Jul 14, 2022

parcelable

Android Parceling support for the Kotlinx Serialization library.
GitHub tag (latest by date)

Badge

val parcelable = Parcelable.Default
parcelable.encodeToBundle(myModel)
val myModel = parcelable.decodeFromBundle(bundle)

Now all the serialization can be handled from a single library, no need to create both custom Parcelers and Serializers. Have a custom class that requires specific serialization? Use the Kotlinx Serialization library and it will automatically work with Android's Parcel, Bundle, and Intent.

Building the library

The library is provided through Repsy.io. Checkout the releases page to get the latest version.
GitHub tag (latest by date)

Repository

repositories {
    maven { url = "https://repo.repsy.io/mvn/chrynan/public" }
}

Dependency

implementation "com.chrynan.parcelable:parcelable-android:$VERSION"

Using the library

  • Setup the Parcelable object:
val parcelable = Parcelable {
    serializersModule = mySerializersModule
}
@Serializable
data class MyModel(
    val intField: Int,
    val stringField: String,
    val nullableStringField: String? = null
)
  • Pass your model through Intents and Bundles:
// Put
intent.putExtra(key, myModel, parcelable)
bundle.putParcelable(key, myModel, parcelable)

// Get
val myModel = intent.getParcelableExtra(key, parcelable)
val myModel = bundle.getParcelable(key, parcelable)
  • Or serialize to and from Parcels and Bundles:
// To
parcelable.encodeToParcel(parcel, myModel)
val bundle = parcelable.encodeToBundle(myModel)

// From
val myModel = parcelable.decodeFromParcel(parcel)
val myModel = parcelable.decodeFromBundle(bundle)

Sample

The sample-android module contains an Android App showcasing the use of this library and providing a means to test parceling different models.

Simply update the ExpectedModel.model value to be any Serializable class and run the application to test if the parceling worked.

Sample Screenshots

Main Screen Results Screen

License

Copyright 2021 chRyNaN

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.

GitHub

https://github.com/chRyNaN/serialization-parcelable
You might also like...

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Codename One - Cross Platform Native Apps with Java or Kotlin Codename One is a mobile first cross platform environment for Java and Kotlin developers

Aug 9, 2022

Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

FancyLocationProvider Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow. Install Add Jitpack repository

Jul 22, 2022

A simple, classic Kotlin MVI implementation based on coroutines with Android support, clean DSL and easy to understand logic

A simple, classic Kotlin MVI implementation based on coroutines with Android support, clean DSL and easy to understand logic

Aug 8, 2022

Template (pure) for KMM application with DI support

KMM di template Template (pure) for KMM application with DI support. Uses Multiplatform-DI for Dependency Injection Features Common architecture (VIP)

Apr 6, 2022

Kotlin multiplatform decorators support

DEKORATOR [WIP] Decorator support for Kotlin! Built with ❤ , powered by Kotlin compiler plugin. Support The plugin only works on targets using new IR

Mar 18, 2022

Backend Project to support providing help to refugees

Project Project to implement the matching of guests and hosts, with special attention to verification of matches. Get it, run it: In order to build th

Apr 9, 2022

[Android Library] A SharedPreferences helper library to save and fetch the values easily.

Preference Helper A SharedPreferences helper library to save and fetch the values easily. Featured in Use in your project Add this to your module's bu

Apr 4, 2020

Oratio Library for Android Studio helps you simplify your Android TTS codes

Oratio Oratio is a library for Android Studio. This library is useful to a number of developers who are currently making apps using android TTS(Text-T

Oct 28, 2021

Android Ptrace Inject for all ABIs and all APIs. Help you inject Shared Library on Android.

Android Ptrace Inject 中文可以参考我的注释内容进行理解 我写的注释相对来说比较全面了 How to build Make sure you have CMake and Ninja in your PATH Edit CMakeLists.txt. Set ANDROID_ND

Aug 12, 2022
Comments
  • 1. Unmarshalling unknown type code 7340148 at offset 8

    Describe the bug There is a bug in library that happens only on Pixel devices.

    Fatal Exception: java.lang.RuntimeException: Parcel [email protected]: Unmarshalling unknown type code 6357038 at offset 8 at android.os.Parcel.readValue(Parcel.java:3305) at android.os.Parcel.readArrayMapInternal(Parcel.java:3623) at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292) at android.os.BaseBundle.unparcel(BaseBundle.java:236) at android.os.Bundle.filterValues(Bundle.java:395) at android.os.Bundle.filterValues(Bundle.java:405) at android.content.Intent.removeUnsafeExtras(Intent.java:8859) at android.app.ActivityThread.handleRequestAssistContextExtras(ActivityThread.java:3890) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2171) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

    I can't reproduce it, but we have a lot of bugs in firebase crashlytics. With no specific case, any screen with your parcelable between intents/fragments inside intent is potential threat.

    Smartphone (please complete the following information):

    • Device: any Pixel
    • OS: android 12

    Additional context It is happening with version 0.3.1, I have simultaneously upgraded to 0.4.1 and will give feedback whether it still happens.

    Reviewed by lepicekmichal at 2022-03-02 10:35
Minecraft NBT support for kotlinx.serialization

knbt An implementation of Minecraft's NBT format for kotlinx.serialization. Technical information about NBT can be found here. Using the same version

Aug 9, 2022
CSV and FixedLength Formats for kotlinx-serialization

Module kotlinx-serialization-csv Serialize and deserialize ordered CSV and Fixed Length Format Files with kotlinx-serialization. Source code Docs Inst

Aug 14, 2022
Kotlin tooling for generating kotlinx.serialization serializers for serializing a class as a bitmask

kotlinx-serialization-bitmask Kotlin tooling for generating kotlinx.serialization serializers for serializing a class as a bitmask. Example @Serializa

May 29, 2022
Auto-generate the fastest possible Parcelable implementations for Java and Kotlin

This project is deprecated It will still be maintained, but no new features will be added. Please use Parcelize, as it is the official way of generati

Jul 29, 2022
Kotlinx-murmurhash - Kotlin Multiplatform (KMP) library for hashing using MurmurHash

kotlinx-murmurhash Kotlin Multiplatform (KMP) library for MurmurHash, a non-cryp

Aug 9, 2022
Automatic CoroutineDispatcher injection and extensions for kotlinx.coroutines

Dispatch Utilities for kotlinx.coroutines which make them type-safe, easier to test, and more expressive. Use the predefined types and factories or de

Jul 31, 2022
Small Kafka Playground to play around with Test Containers, and KotlinX Coroutines bindings while reading Kafka Definite Guide V2

KafkaPlayground Small playground where I'm playing around with Kafka in Kotlin and the Kafka SDK whilst reading the Kafka book Definite Guide from Con

Jul 22, 2022
An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines.

one An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines. Feature Transform different data structs to one. {errorCode, d

Jul 24, 2022
A Kotlin work manager library for Android with progress notifications and Hilt support.

Boot Laces A kotlin work manager library for Android that includes notifications and Hilt support. User Instructions Add the JitPack repository to you

Jul 17, 2022
Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

Jul 26, 2022