An interop tool for safely mixing Moshi and Gson models in JSON serialization.
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.
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.
You can use the Moshi.interopBuilder()
extension to create an InteropBuilder
for advanced usage and adding
your own ClassChecker
logic.
dependencies {
implementation("com.slack.moshi:gson-interop:<version>")
}
Snapshots of the development version are available in Sonatype’s snapshots
repository.
nextSource()
or valueSink()
APIs. This means that it
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.