Skip to content

Releases: ZacSweers/MoshiX

0.18.3

01 Jul 20:36
Compare
Choose a tag to compare
  • Fix: Support @Json.ignore in MetadataKotlinJsonAdapterFactory.

What's Changed

Full Changelog: 0.18.2...0.18.3

0.18.2

29 Jun 17:45
Compare
Choose a tag to compare

Highlights

  • Fix: Incremental processing when sealed types are spread across multiple files now works
    correctly for KSP code gen in moshi-sealed. Thanks to @efemoney
  • Update KotlinPoet to 1.12.0
  • Update kotlinx-metadata to 0.5.0

What's Changed

  • Update plugin spotless to v6.7.2 by @renovate in #294
  • Update okhttp to v4.10.0 by @renovate in #295
  • Update kotlinpoet to v1.12.0 by @renovate in #296
  • Update kotlinCompileTesting to v1.4.9 by @renovate in #297
  • Update plugin kotlinBinaryCompatibilityValidator to v0.10.1 by @renovate in #300
  • Update dependency com.facebook:ktfmt to v0.39 by @renovate in #301
  • Update dependency org.jetbrains.kotlinx:kotlinx-metadata-jvm to v0.5.0 by @renovate in #302
  • Support sealed subclasses defined in separate files by @efemoney in #299

Full Changelog: 0.18.1...0.18.2

0.18.1

11 Jun 19:40
Compare
Choose a tag to compare

Add a missing proguard rule for @AdaptedBy annotations to ensure they're kept on classes that use
them. Unfortunately there doesn't appear to be a more granular way preserve these annotations without
also keeping the whole class.

0.18.0

10 Jun 15:27
Compare
Choose a tag to compare
  • Update to Kotlin 1.7.0 (Kotlin 1.6.x is no longer supported).
  • Remove remaining use of deprecated descriptor APIs in IR.
  • Update to KSP 1.7.0-1.0.6

0.17.2

28 May 00:54
Compare
Choose a tag to compare

Fix: Fix IR lookups of setOf() overloads. There are two setOf() functions with one arg - one
is the vararg and the other is a shorthand for Collections.singleton(element). It's important we
pick the right one, otherwise we can accidentally send a vararg array into the singleton()
function.

Dependency updates:

Kotlin 1.6.21
kotlinpoet 1.11.0
kotlinx-metadata 0.4.2

0.17.1

09 Mar 19:14
f7e4da9
Compare
Choose a tag to compare

Fix: Fix support for nested sealed types that don't use @JsonClass.

0.17.0

16 Feb 20:41
c17999d
Compare
Choose a tag to compare

New: moshi-sealed now supports nested sealed subtypes!

In some cases, it's useful to have more than one level of sealed types that share the same label key.

sealed interface Response {
  data class Success(val value: String) : Response
  sealed interface Failure : Response {
   data class ErrorMap(val errors: List<String>) : Failure
   data class ErrorString(val error: String) : Failure
  }
}

moshi-sealed now supports this out of the box via @NestedSealed annotation. Simply indicate the nested type with this
annotation.

@JsonClass(generateAdapter = true, generator = "sealed:type")
sealed interface Response {
  @TypeLabel("success")
  @JsonClass(generateAdapter = true)
  data class Success(val value: String) : Response

  @NestedSealed
  sealed interface Failure : Response {
    @TypeLabel("error_map")
    @JsonClass(generateAdapter = true)
    data class ErrorMap(val errors: List<String>) : Failure

    @TypeLabel("error_string")
    @JsonClass(generateAdapter = true)
    data class ErrorString(val error: String) : Failure
  }
}

In this case, now Failure's subtypes will also participate in Response decoding based on the type label key.

Caveats:

  • @DefaultObject is only supported on direct subtypes.
  • If you want to look up a subtype rather than the root parent sealed type (i.e. moshi.adapter<Response.Failure>()),
    you must add the optional NestedSealed.Factory JsonAdapter.Factory to your Moshi instance for runtime lookup.
    val moshi = Moshi.Builder()
      .add(NestedSealed.Factory())
      .build()

Kapt is no longer supported by moshi-sealed

moshi-sealed has many implementations - kotlin-reflect, kotlinx-metadata, KSP, Java sealed classes, and
recently IR. These are a lot to maintain! To cut down on maintenance, Kapt is no longer supported and has been removed
in this release. Please consider migrating to KSP or Moshi-IR.

Fix: Properly report all originating files in KSP

With Kotlin 1.5.0, sealed types could now exist across multiple files. moshi-sealed's KSP support previously assumed single files when reporting originating elements, and now properly reports all files if sealed types are spread across multiple files.

0.16.7

01 Feb 19:38
89e1541
Compare
Choose a tag to compare

moshi-ir

  • Fix: Use FilesSubpluginOption to fix build cache relocatability when generating proguard rules.

0.16.6

27 Jan 07:27
Compare
Choose a tag to compare

moshi-ir

  • Fix: Nested type argument use in properties would fail in 0.16.5's new type rendering. This is now fixed.
    Example failing case would've been something like this:
    @JsonClass(generateAdapter = true)
    class Foo<T>(val value: List<T>)

0.16.5

21 Jan 02:57
d7c7b1d
Compare
Choose a tag to compare
  • Enhancement: Generate manual Type construction in moshi-ir adapter lookups. Prior to this, we generated IR
    code that leveraged typeOf(), but this appears to be too late to leverage compiler intrinsics support for it and
    appears to cause some issues if kotlin-reflect is on the classpath. This should improve runtime performance as a
    result.