Moshi v1.11.0 Release Notes

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