Coder Social home page Coder Social logo

romankivalin / moshi-gson-interop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from slackhq/moshi-gson-interop

0.0 0.0 0.0 114 KB

An interop tool for safely mixing Moshi and Gson models in JSON serialization.

License: Apache License 2.0

Shell 2.71% Kotlin 97.29%

moshi-gson-interop's Introduction

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.

Installation

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, Inc.

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.

moshi-gson-interop's People

Contributors

cketti avatar roach avatar zacsweers avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.