Android Bundle format support for Kotlinx Serialization.

Overview

Bundlizer CI Maven Central

Android Bundle format support for Kotlinx Serialization.

Usage

Annotate your data models with @Serializable:

import kotlinx.serialization.Serializable

enum class Type {
    HUMAN, MONKEY
}

@Serializable
data class Email(val value: String)

@Serializable
data class User(
    val id: Int,
    val name: String,
    val email: Email,
    val friends: List<String>?,
    val something: Map<String, Int>,
    val type: Type
)

To Bundle

Use Bundlizer.bundle or bundle extension function:

import dev.ahmedmourad.bundlizer.Bundlizer
import dev.ahmedmourad.bundlizer.bundle
import android.os.Bundle

val user: User = ...

val bundle: Bundle = Bundlizer.bundle(User.serializer(), user)
// or
val bundle: Bundle = user.bundle(User.serializer())

From Bundle

Use Bundlizer.unbundle or unbundle extension function:

import dev.ahmedmourad.bundlizer.Bundlizer
import dev.ahmedmourad.bundlizer.unbundle
import android.os.Bundle

val bundle: Bundle = ...

val user: User = Bundlizer.unbundle(User.serializer(), bundle)
// or
val user: User = bundle.unbundle(User.serializer())

Installation

repositories {
    mavenCentral()
}

dependencies {
    implementation "dev.ahmedmourad.bundlizer:bundlizer-core:0.5.0"
}

License

Copyright (C) 2020 Ahmed Mourad

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.
You might also like...
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

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

Kotlinx-murmurhash - Kotlin Multiplatform (KMP) library for hashing using MurmurHash

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

Slime World Format implementation written in Kotlin with Zstd for bukkit.

Slime Korld Easily create many slime worlds with the Slime Korld. What is Slime Korld? Slime Korld is a bukkit library written in Kotlin to make minec

Jackson extension for Mojang's NBT format

Jackson NBT Data Format Implements Mojang's NBT format in jackson. Usage Using this format works just like regular jackson, but with the ObjectMapper

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

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

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

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

Comments
  • Fix list encoding

    Fix list encoding

    Problem:

    In current version, encoding of top level List structure can't be decoded because don't contains size field.

    Example:

    // Exists items in adapter. 
    val bundle = adapter.items.bundle(ListSerializer(Item.serializer()))
    
    val items = state.unbundle(ListSerializer(Item.serializer()))
    // items size = 0
    

    Solution:

    Moved adding size key to before keyInParent to fix issue. I don't sure what nothing was not broken by this change, please verify solution.

    bug good first issue 
    opened by Starmel 2
  • Cannot provide SerializersModule to Bundle[Encoder/Decoder]

    Cannot provide SerializersModule to Bundle[Encoder/Decoder]

    Example:

    @Serializable
    data class AppState(
        val slices: Map<String, @Polymorphic Any>
    )
    
    @Serializable
    data class FeatureState1(...)
    
    @Serializable
    data class FeatureState2(...)
    

    My @Polymorphic Any type parameter can be FeatureState1 or FeatureState2. So what i do :

    val module = SerializersModule {
        polymorphic(Any::class) {
            subclass(FeatureState1::class)
            subclass(FeatureState2::class)
        }
    }
    

    And then i can't provide "module" for Bundle[Encoder/Decoder] in

    Bundlizer.bundle(AppState.serializer(), appstate)

    so got error here ^.

    It would be good to have optional parameter of type SerializersModule with default value "EmptySerializersModule".

    opened by AntonAzaryan 1
Releases(v0.7.0)
Owner
Ahmed Mourad
Android Developer
Ahmed Mourad
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

Ben Woodworth 41 Dec 21, 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

Philip Wedemann 12 Dec 16, 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

marie 2 May 29, 2022
Type-safe arguments for JetPack Navigation Compose using Kotlinx.Serialization

Navigation Compose Typed Compile-time type-safe arguments for JetPack Navigation Compose library. Based on KotlinX.Serialization. Major features: Comp

Kiwi.com 32 Jan 4, 2023
KotlinX Serialization Standard Serializers (KS3)

KotlinX Serialization Standard Serializers (KS3) This project aims to provide a set of serializers for common types. ⚠️ Consider this project to be Al

Emil Kantis 3 Nov 5, 2022
A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio

Store A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisatio

Isuru Rajapakse 98 Jan 3, 2023
A mindustry mod that shuffles both the texture atlas and bundle

ohno amogus Total chaos Mindustry mod that shuffles both the texture atlas and the current bundle, providing an unforgettable gaming experience Comes

Мнемотехник 4 Sep 3, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Practical Kotlin Multiplatform on the Web 본 저장소는 코틀린 멀티플랫폼 기반 웹 프로그래밍 워크숍(강좌)을 위해 작성된 템플릿 프로젝트가 있는 곳입니다. 워크숍 과정에서 코틀린 멀티플랫폼을 기반으로 프론트엔드(front-end)는 Ko

SpringRunner 14 Nov 5, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Building a Full Stack Web App with Kotlin Multiplatform 본 저장소는 INFCON 2022에서 코틀린 멀티플랫폼 기반 웹 프로그래밍 핸즈온랩을 위해 작성된 템플릿 프로젝트가 있는 곳입니다. 핸즈온 과정에서 코틀린 멀티플랫폼을

Arawn Park 19 Sep 8, 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

Rick Busarow 132 Dec 9, 2022