All Projects → aafanasev → Kson

aafanasev / Kson

Licence: mit
Gson TypeAdapter & Factory generator for Kotlin data classes

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kson

Gsonpath
A Java annotation processor library which generates gson type adapters using basic JsonPath style annotations
Stars: ✭ 54 (-40%)
Mutual labels:  annotation-processor, json, gson
Configurate
A simple configuration library for Java applications providing a node structure, a variety of formats, and tools for transformation
Stars: ✭ 148 (+64.44%)
Mutual labels:  json, gson
Immutables
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included
Stars: ✭ 3,031 (+3267.78%)
Mutual labels:  annotation-processor, gson
Kripton
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.
Stars: ✭ 110 (+22.22%)
Mutual labels:  annotation-processor, json
Jsonformat4flutter
受zzz40500/GsonFormat启发,将JSONObject格式的String解析成dart语言的实体类
Stars: ✭ 411 (+356.67%)
Mutual labels:  json, gson
Jsonschema2pojo
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Stars: ✭ 5,633 (+6158.89%)
Mutual labels:  json, gson
Moshix
Moshi Extensions
Stars: ✭ 243 (+170%)
Mutual labels:  annotation-processor, json
Bandcamp Api
API wrapper for querying band, album, and track data from bandcamp.com
Stars: ✭ 20 (-77.78%)
Mutual labels:  json, gson
Easyjson
Provides an unified JSON access API, you can adapter any JSON library to Gson, Jackson, FastJson with easyjson。 提供了一个JSON门面库,就像slf4j一样。easyjson本身不做json的操作,完全依赖于底层实现库。可以直接使用Easyjson的API,底层的JSON库随时可切换。也可以使用其中某个json的API,然后通过easyjson适配给其他的json库
Stars: ✭ 54 (-40%)
Mutual labels:  json, gson
Rpushbullet
R interface to the awesome Pushbullet service
Stars: ✭ 84 (-6.67%)
Mutual labels:  json
Pager Api
Easy API pagination for Rails
Stars: ✭ 86 (-4.44%)
Mutual labels:  json
Cesium
cesium demo,cesium 研究过程中资料整理,包括: 1、示例,提供常规的cesium示例以及综合性的业务示例 2、工具,整理研究过程中写的一些数据获取、处理、分析的工具,例如网络3dtiles数据爬虫工具、b3dm 转 gltf工具 3、插件,根据研究过程中cesium感觉使用不方便的地方,添加插件,包括针对显示控件的汉化中文语言插件等
Stars: ✭ 84 (-6.67%)
Mutual labels:  json
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (-5.56%)
Mutual labels:  json
Openfintech
Opensource FinTech standards & payment provider data
Stars: ✭ 87 (-3.33%)
Mutual labels:  json
Jaydiff
A JSON diff utility
Stars: ✭ 84 (-6.67%)
Mutual labels:  json
Redisjson Py
An extension to redis-py for using Redis' ReJSON module
Stars: ✭ 89 (-1.11%)
Mutual labels:  json
Dahomey.json
The main purpose of this library is to bring missing features to the official .Net namespace System.Text.Json
Stars: ✭ 84 (-6.67%)
Mutual labels:  json
Redisjson
RedisJSON - a JSON data type for Redis
Stars: ✭ 1,239 (+1276.67%)
Mutual labels:  json
Summitdb
In-memory NoSQL database with ACID transactions, Raft consensus, and Redis API
Stars: ✭ 1,295 (+1338.89%)
Mutual labels:  json
Pyon
The Pythonic way to use JSON - with native objects 🛠 and path support 📁
Stars: ✭ 88 (-2.22%)
Mutual labels:  json

Download Android Arsenal

Kson - kotlin type adapter generator

An annotation processor generates Gson TypeAdapter from Kotlin Data Classes

Motivation

By default, Gson uses reflection to read/write data from JSON. It's not only slow (benchmarks), also it breaks Kotlin's null-safe types.

For example:

// your entity class with non-nullable property
data class Entity(val id: Int)

// wrong response from server
val json = """{ "id": null }"""

// this won't throw error
val entity = gson.fromJson(json, Entity::class.java)

// throws NPE somewhere in runtime when you don't expect
entity.id

In order to avoid reflection, need to create a custom TypeAdapter for every entity class. It takes time, need to write boilerplate code, tests, etc. Here this library comes, it generates TypeAdapters automatically. You just need to register generated GsonTypeAdapterFactory in your GsonBuilder.

Usage

Add @Kson annotation to your data classes and Kson will automatically generate <class name>TypeAdapter.kt files.

@Kson
data class RoleEntity(
    val id: Int, 
    @SerializedName("roleName") val name: String
)

@Kson
data class UserEntity(
    val firstname: String,
    val lastname: String,
    val roles: List<RoleEntity>
)

// etc

Also you can use @KsonFactory annotation to generate TypeAdapterFactory class

@KsonFactory
object FactoryProvider {

    get() = KsonFactoryProvider()

}

val gson = GsonBuilder()
    .registerTypeAdapterFactory(FactoryProvider.get())
    .create()

// gson.fromJson(...)

Limitations & Known issues

Since this is an early version there are some unsupported properties

@Kson
data class UnsupportedDataClass(
    @JsonAdapter(CustomAdapter::class) val id: String // custom type adapter
    val name: String = "no name" // default values
    val list: List<String?> // nullable generics
    val `natural name`: String // "natural names"
)

Installation

To add KSON to your project, add the following to your module's build.gradle:

repositories {
    jcenter()
}

dependencies {
    compile 'dev.afanasev:kson-annotation:<version>'   
    kapt 'dev.afanasev:kson-processor:<version>'
}

Mentions

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].