Skip to content

LunarWatcher/KClassUnpacker

Repository files navigation

Setup

If you haven't already, link Jitpack:

repositories {
    // ...
    maven { url 'https://jitpack.io' }
}

Add the processor:

apply plugin: 'kotlin-kapt'
...

dependencies {
    kapt 'com.github.LunarWatcher:KClassUnpacker:$version'
    compileOnly "com.github.LunarWatcher:KClassUnpacker:$version"
}

Where $version is either a variable, or the version you want to use in plain text (in which case, replace it with the version you want). The available versions can be seen in the releases

Usage

Annotate a data class with @AutoUnpack. After that, you can write code like:

for(field in someDataClass) {
    do something with the fields
}

Motivation

This post on SO.

License

Because the code is posted on SO as well, the license is CC-BY-SA 3.0 here too (the same as the SO post is licensed under), to avoid licensing conflicts between the repo and the post. So whether you copy the code or use the dependency, the licenses are identical.