All Projects → slackhq → moshi-gson-interop

slackhq / moshi-gson-interop

Licence: Apache-2.0 license
An interop tool for safely mixing Moshi and Gson models in JSON serialization.

Programming Languages

kotlin
9241 projects
shell
77523 projects

Projects that are alternatives of or similar to moshi-gson-interop

Jsontokotlinclass
🚀 Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )
Stars: ✭ 2,438 (+6151.28%)
Mutual labels:  gson, moshi
json-serialization-benchmarking
Miscellaneous benchmarks for JSON serialization on JVM/Android
Stars: ✭ 48 (+23.08%)
Mutual labels:  gson, moshi
Gankioclient
利用干货集中营的API自制练手之作
Stars: ✭ 63 (+61.54%)
Mutual labels:  gson
Gsonpath
A Java annotation processor library which generates gson type adapters using basic JsonPath style annotations
Stars: ✭ 54 (+38.46%)
Mutual labels:  gson
Redgram For Reddit
An Open-Sourced Android Reddit Client
Stars: ✭ 106 (+171.79%)
Mutual labels:  gson
Kson
Gson TypeAdapter & Factory generator for Kotlin data classes
Stars: ✭ 90 (+130.77%)
Mutual labels:  gson
Phoenix For Vk
Yet another VK client for Android
Stars: ✭ 131 (+235.9%)
Mutual labels:  gson
Gson Jodatime Serialisers
A set of Gson serialiser/deserialisers for dealing with Joda Time entities.
Stars: ✭ 107 (+174.36%)
Mutual labels:  gson
Trailersapp
A simple demo project for The Movie DB based on MVVM clean architecture.
Stars: ✭ 180 (+361.54%)
Mutual labels:  gson
Seppb
普兰能效平台开源版(后端)
Stars: ✭ 104 (+166.67%)
Mutual labels:  gson
Rxcache
A local reactive cache for Java and Android. Now, it supports heap memory、off-heap memory and disk cache.
Stars: ✭ 102 (+161.54%)
Mutual labels:  gson
Todo
简洁清爽的Todo清单工具❤️ (MVP+okhttp3+retrofit+gson)
Stars: ✭ 93 (+138.46%)
Mutual labels:  gson
Gson Plugin
辅助 Gson 库的 gradle 插件,防止 Json 数据解析类型异常。
Stars: ✭ 133 (+241.03%)
Mutual labels:  gson
Moviefinderusingmvvm Android
🔥 MVVM + Clean Architecture + Best Practices | 🍿Movie Finder is a sample Android application 📱to search movies using OMDb API which is built to demonstrate use of Modern Android development tools - (Kotlin, Coroutines, Kodein, Architecture Components, MVVM, Retrofit, Gson, Material Components) 😊😊😉
Stars: ✭ 66 (+69.23%)
Mutual labels:  gson
Gsonfactory
Gson 解析容错框架,愿从此再无 Json 解析报错
Stars: ✭ 188 (+382.05%)
Mutual labels:  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 (+38.46%)
Mutual labels:  gson
Apiclient
A easy to use api client that combines the power of Retrofit, Realm, Gson, Rxjava and Retrolambda in a easy to use library for Java and Android
Stars: ✭ 100 (+156.41%)
Mutual labels:  gson
RxjavaSamples
This repo is a container for some samples using RXJAVA2 samples
Stars: ✭ 12 (-69.23%)
Mutual labels:  gson
ConfigAPI
GSON-like ORM for Bukkit YAML API's
Stars: ✭ 23 (-41.03%)
Mutual labels:  gson
Okhttp Volley Gson
Sample app showcasing Android Networking with OkHttp, Volley and Gson. Check out the article to further explanation.
Stars: ✭ 235 (+502.56%)
Mutual labels:  gson

moshi-gson-interop

A tool for bidirectional interop between Moshi and Gson.

This is targeted at codebases that are in the process of migrating from Gson to Moshi and not a general-purpose tool that should be used for other reasons.

Usage

In order to properly link two Moshi and Gson instances, you must pass two complete instances (i.e. not intended to newBuilder() later) to Moshi.interopWith() and use the returned instances.

val seedMoshi: Moshi = ...
val seedGson: Gson = ...

// Use the returned instances!
val (moshi, gson) = seedMoshi.interopWith(seedGson)

By default, the interop mechanism will attempt to best-guess which serializer to use based on a combination of things (see DefaultMoshiClassChecker's kdoc). You can alternatively provide your own logic for this.

Advanced

You can use the Moshi.interopBuilder() extension to create an InteropBuilder for advanced usage and adding your own ClassChecker logic.

Installation

Maven Central

dependencies {
  implementation("com.slack.moshi:gson-interop:<version>")
}

Snapshots of the development version are available in Sonatype's snapshots repository.

Caveats

  • JsonQualifiers on a type in a Gson class will not be passed on to Moshi, as Gson (and the various tools around it) don't capture them.
  • Performance
    • A Moshi adapter delegating to Gson should have no performance issues as it is able to stream data directly.
    • Streaming from Gson to Moshi will, however, be degraded as Gson has no equivalent streaming APIs to Moshi's nextSource() or valueSink() APIs. This means that it must either decode the entire source into an intermediary object (i.e. a Map, List, etc) first when reading or encode the entire value into a JSON String first when writing.

License

Copyright 2020 Slack Technologies, LLC

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.
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].