0.20.0
New: @FallbackJsonAdapter
moshi-sealed now supports a new @FallbackJsonAdapter
. This is a proxy to Moshi's PolymorphicJsonAdapter.withFallbackJsonAdapter()
. This allows you to specify a custom JsonAdapter
to handle cases of unrecognized type labels in decoding. It's advanced usage and not recommended for regular cases.
The specified JsonAdapter
must have a public constructor with no parameters or a single Moshi
parameter.
@FallbackJsonAdapter(FrogFallbackJsonAdapter::class)
@JsonClass(generateAdapter = true, generator = "sealed:type")
sealed class Frog {
@JsonClass(generateAdapter = true)
@TypeLabel("original", null)
data class OriginalFrog(...)
@JsonClass(generateAdapter = true)
@TypeLabel("poisonous")
data class PoisonousFrog(...)
class FrogFallbackJsonAdapter(moshi: Moshi) : JsonAdapter<Frog>() {
private val delegate = moshi.adapter<OriginalFrog>()
override fun fromJson(reader: JsonReader): Frog? {
// Default to original frog
return delegate.fromJson(reader)
}
//...
}
}
New: Experimental support for the new K2 compiler in moshi-ir.
Edit: this isn't usable in this release, don't try to use it!
Misc
- Enhancement: Generate extra proguard rules for
@NestedSealed
types to prevent R8 from inlining the parent sealed type into the subtype in some cases. - Enhancement: Proguard generation in moshi-ir now uses Anvil's more optimized compiler util APIs.
- Enhancement: Check and report more error cases in moshi-ir and moshi-sealed code gen.
- Fix: moshi-ir now properly generates proguard rules for moshi-sealed types.
- Fix: track
@NestedSealed
types as originating files in moshi-sealed KSP. - Enhancement: Substantially improved KSP and IR test coverage of error cases.
- Update to Kotlin
1.7.22
. - Update to KSP
1.7.22-1.0.8
.
What's Changed
- Update plugin dokka to v1.7.20 by @renovate in #334
- Update dependency com.android.tools.build:gradle to v7.3.1 by @renovate in #335
- Update ksp to v1.7.20-1.0.7 by @renovate in #336
- Update plugin kotlinBinaryCompatibilityValidator to v0.12.0 by @renovate in #337
- Update plugin kotlinBinaryCompatibilityValidator to v0.12.1 by @renovate in #338
- Update plugin org.jetbrains.kotlin.jvm to v1.7.20 by @renovate in #339
- Update ksp to v1.7.20-1.0.8 by @renovate in #340
- Update ksp to v1.7.21-1.0.8 by @renovate in #343
- Update plugin spotless to v6.12.0 by @renovate in #344
- Update dependency gradle to v7.6 by @renovate in #345
- Switch to maintained KCT + support K2 in some places by @ZacSweers in #347
- Update ksp to v1.7.22-1.0.8 by @renovate in #346
- Update kotlin monorepo to v1.7.22 by @renovate in #341
- Generate extra proguard rules to keep parent sealed adapters for subclass usages by @ZacSweers in #348
- Implement
@FallbackJsonAdapter
by @ZacSweers in #350
Full Changelog: 0.19.0...0.20.0