All Versions
21
Latest Version
Avg Release Cycle
117 days
Latest Release
-

Changelog History
Page 1

  • v1.14.0 Changes

    • Upgrade: [Kotlin 1.7.0][kotlin_1_7_0].
    • Upgrade [KotlinPoet 1.12.0][kotlinpoet_1_12_0].
      • Moshi no longer shades kotlinpoet-ksp APIs, meaning they can be updated independently of Moshi updates.
    • Upgrade: [KSP 1.7.0-1.0.6][ksp_1_7_0_1_0_6].
    • Upgrade: [kotlinx-metadata 0.5.0][kotlinx_metadata_0_5_0], allowing reading of kotlin 1.8 APIs too.
  • v1.13.0 Changes

    2021-12-08

    • New: Support for [Kotlin Symbol Processing (KSP)][ksp]. KSP is an alternative to annotation processing code gen. It's builds faster and better supports Kotlin language features.

    To use KSP in your application you must enable the KSP Gradle plugin and add a KSP dependency on Moshi codegen.

    ```
    plugins {
      id("com.google.devtools.ksp").version("1.6.0-1.0.1")
    }
    
    dependencies {
      ksp("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")
    }
    ```
    

    If you're switching from annotation processing (kapt) to KSP, you should remove the kapt plugin and the kapt Moshi dependency.

    • New: @Json(ignore = true) is a Moshi-specific way to exclude properties from JSON encoding and decoding.
    • New: Support Java 16 records. (Moshi still requires Java 8 only; we're shipping a [multi-release jar][mrjar] to better support modern JVMs.)
    • New: Option to disable generating R8/ProGuard files. These files prevent code shrinkers from removing files that support JSON processing. If you're not using ProGuard or R8, you can skip this step.

      ksp {
        arg("moshi.generateProguardRules", "false")
      }
      
    • Upgrade: [Kotlin 1.6.0][kotlin_1_6_0].

  • v1.12.0 Changes

    2021-04-01

    • New: Improve generated code performance when all properties are set.
    • Fix: Don't crash on a missing type element like @SuppressLint.
    • Fix: Update the JVM metadata library to avoid problems on Kotlin 1.5.0-M2.
    • Fix: Support generic arrays with defaults in generated adapters.
    • Fix: Don't generate code with simple name collisions.
    • Upgrade: [Okio 2.10.0][okio_2_10_0].
    • Upgrade: [Kotlin 1.4.31][kotlin_1_4_31].
  • v1.11.0 Changes

    2020-10-04

    • New: Kotlin extension functions and properties. Use of these extensions is only possible from Kotlin, and requires the Kotlin stdlib dependency. This release does not have any Kotlin requirement and can be used Kotlin-free from Java.

      /** Extension alternative to [Types.nextAnnotations()]. */
      fun <reified T : Annotation> Set<Annotation>.nextAnnotations(): Set<Annotation>?
      
      /** Extension alternative to [Types.getRawType()]. */
      val Type.rawType: Class<*>
      
      /** Extension alternative to [Types.arrayOf()]. */
      fun KClass<*>.asArrayType(): GenericArrayType
      
      /** Extension alternative to [Types.arrayOf()]. */
      fun Type.asArrayType(): GenericArrayType
      
    • New: Experimental Kotlin extensions. These depend on unreleased APIs and may break in a future release of Kotlin. If you are comfortable with this, add @ExperimentalStdlibApi at the callsite or add this argument to your Kotlin compiler: "-Xopt-in=kotlin.ExperimentalStdlibApi".

      /** Returns the adapter for [T]. */
      inline fun <reified T> Moshi.adapter(): JsonAdapter<T>
      
      /** Returns the adapter for [ktype]. */
      fun <T> Moshi.adapter(ktype: KType): JsonAdapter<T>
      
      /** Adds an adapter for [T]. */
      inline fun <reified T> Moshi.Builder.addAdapter(adapter: JsonAdapter<T>): Moshi.Builder
      
      /** Extension alternative to [Types.arrayOf()]. */
      fun KType.asArrayType(): GenericArrayType
      
      /** Extension alternative to [Types.subtypeOf()]. */
      inline fun <reified T> subtypeOf(): WildcardType
      
      /** Extension alternative to [Types.supertypeOf()]. */
      inline fun <reified T> supertypeOf(): WildcardType
      
    • New: JsonReader.nextSource(). This returns an Okio BufferedSource that streams the UTF-8 bytes of a JSON value. Use this to accept JSON values without decoding them, to delegate to another JSON processor, or for streaming access to very large embedded values.

    • New: Moshi.Builder.addLast(). Use this when installing widely-applicable adapter factories like KotlinJsonAdapterFactory. Adapters registered with add() are preferred (in the order they were added), followed by all adapters registered with addLast() (also in the order they were added). This precedence is retained when Moshi.newBuilder() is used.

    • New: setTag(), tag() methods on JsonReader and JsonWriter. Use these as a side-channel between adapters and their uses. For example, a tag may be used to track use of unexpected data in a custom adapter.

    • Fix: Don't crash with a StackOverflowError decoding backward-referencing type variables in Kotlin. This caused problems for parameterized types like MyInterface<E : Enum<E>>.

    • Upgrade: [Okio 1.17.5][okio_1_7_5].

    • Upgrade: [Kotlin 1.4.10][kotlin_1_4_10].

  • v1.10.0 Changes

    2020-08-26

    • New: Upgrade to Kotlin 1.4.0.
    • New: JsonReader.promoteNameToValue() makes it easier to build custom Map adapters.
    • New: Options.strings().
    • New: PolymorphicJsonAdapterFactory.withFallbackJsonAdapter() makes it possible to handle unrecognized types when encoding and decoding.
    • New: Add JsonWriter.jsonValue API
    • New: Code gen now generates precise proguard rules on-the-fly.
    • New: Improve error when incorrectly trying to use a collection class like ArrayList instead of List
    • Fix: Prevent R8 from keeping all @Metadata annotations
    • Fix: Avoid VerifyErrors on Android 4.4 devices when using R8
    • Fix: Fix resolution of types in superclass settable properties
  • v1.9.3 Changes

    2020-06-11

    • Fix: Tweak a shrinker rule to mitigate an R8 bug which was causing classes unrelated to the Kotlin adpater code generation to be retained.
    • Fix: Ensure that the Kotlin adapter code generation does not line wrap in the middle of a string if your JSON keys contain spaces.
    • Fix: Strip type annotations before emitting type references like Foo::class in the Kotlin adapter code generation.
    • Fix: Separate the runtime check for Kotlin's DefaultConstructorMarker from the check for Metadata. A shrinker may have removed Metadata and we should still check for DefaultConstructorMarker.
  • v1.9.2 Changes

    November 17, 2019

    2019-11-17

    • Fix: Generate correct adapters for several special cases including reified inline types, public classes enclosed in internal classes, deprecated types with -Werror, primitives in type parameters, nullables in type parameters, and type aliases in type parameters.
  • v1.9.1 Changes

    October 31, 2019

    2019-10-30

    • Fix: "abstract function ... cannot have code" code gen crash when parsing Kotlin metadata.
    • Fix: Generate code to support constructors with more than 32 parameters. The 1.9.0 release had a regression where classes with 33+ parameters would crash upon decoding.
    • Fix: Generate code to support more constructor cases, such as classes with non-property parameters and classes with multiple constructors.
    • Fix: Generate code to handle type aliases in type parameters.
  • v1.9.0 Changes

    October 29, 2019

    2019-10-29

    • This release requires kotlin-reflect or moshi-kotlin-codegen for all Kotlin classes.

    Previously Moshi wouldn't differentiate between Kotlin classes and Java classes if Kotlin was not configured. This caused bad runtime behavior such as putting null into non-nullable fields! If you attempt to create an adapter for a Kotlin type, Moshi will throw an IllegalArgumentException.

    Fix this with either the reflection adapter:

       val moshi = Moshi.Builder()
           // ... add your own JsonAdapters and factories ...
           .add(KotlinJsonAdapterFactory())
           .build()
    

    Or the codegen annotation processor:

       @JsonClass(generateAdapter = true)
       data class BlackjackHand(
               val hidden_card: Card,
               val visible_cards: List<Card>
       )
    

    The [Kotlin documentation][moshi_kotlin_docs] explains the required build configuration changes.

    • New: Change how Moshi's generated adapters call constructors. Previous generated code used a combination of the constructor and copy() method to set properties that have default values. With this update we call the same synthetic constructor that Kotlin uses. This is less surprising though it requires us to generate some tricky code.
    • New: Make Rfc3339DateJsonAdapter null-safe. Previously Moshi would refuse to decode null dates. Restore that behavior by explicitly forbidding nulls with Rfc3339DateJsonAdapter().nonNull().
    • New: Require Kotlin 1.3.50 or newer.
    • New: JsonWriter.valueSink() streams JSON-formatted data inline. Use this to do basic includes of raw JSON within a streamed document.
    • New: Support Gradle incremental processing in code gen.
    • New: Improve error messages. This includes better errors when field names and JSON names disagree, and when failing on an unknown field.
    • New: Support default values in PolymorphicJsonAdapterFactory.
    • New: Permit multiple labels for each subtype in PolymorphicJsonAdapterFactory. The first label is used when writing an object to JSON.
    • New: Forbid automatic encoding of platform classes in kotlinx. As with java.*, android.*, and kotlin.* Moshi wants you to specify how to encode platform types.
    • New: @JsonClass(generator=...) makes it possible for third-party libraries to provide generated adapters when Moshi's default adapters are insufficient.
    • Fix: Simplify wildcard types like List<? extends Number> to their base types List<Number> when finding type adapters. This is especially useful with Kotlin where wildcards may be added automatically.
    • Fix: Use the correct name when the @Json annotation uses field targeting like @field:Json.
    • Fix: Support multiple transient properties in KotlinJsonAdapter.
    • Fix: Don't explode attempting to resolve self-referential type variables like in Comparable<T extends Comparable<T>>.
    • Fix: Don't infinite loop on skipValue() at the end an object or array. Also disallow calling skipValue() at the end of a document.
  • v1.8.0 Changes

    November 08, 2018

    2018-11-09

    • New: Support JSON objects that include type information in the JSON. The new PolymorphicJsonAdapterFactory writes a type field when encoding, and reads it when decoding.
    • New: Fall back to the reflection-based KotlinJsonAdapterFactory if it is enabled and a generated adapter is not found. This makes it possible to use reflection-based JSON adapters in development (so you don't have to wait for code to be regenerated on every build) and generated JSON adapters in production (so you don't need the kotlin-reflect library).
    • New: The peekJson() method on JsonReader let you read ahead on a JSON stream without consuming it. This builds on Okio's new Buffer.peek() API.
    • New: The beginFlatten() and endFlatten() methods on JsonWriter suppress unwanted nesting when composing adapters. Previously it was necessary to flatten objects in memory before writing.
    • New: Upgrade to Okio 1.16.0. We don't yet require Kotlin-friendly Okio 2.1 but Moshi works fine with that release.
       implementation("com.squareup.okio:okio:1.16.0")
    
    • Fix: Don't return partially-constructed adapters when using a Moshi instance concurrently.
    • Fix: Eliminate warnings and errors in generated .kt triggered by type variance, primitive types, and required values.
    • Fix: Improve the supplied rules (moshi.pro) to better retain symbols used by Moshi. We recommend R8 when shrinking code.
    • Fix: Remove code generation companion objects. This API was neither complete nor necessary.