Releases: ZacSweers/MoshiX
0.18.3
- Fix: Support
@Json.ignore
inMetadataKotlinJsonAdapterFactory
.
What's Changed
- Update plugin dokka to v1.7.0 by @renovate in #303
- Update plugin spotless to v6.8.0 by @renovate in #304
- Support
@Json.ignore
in MetadataKotlinJsonAdapterFactory by @ZacSweers in #306
Full Changelog: 0.18.2...0.18.3
0.18.2
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
0.18.0
0.17.2
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
0.17.0
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 optionalNestedSealed.Factory
JsonAdapter.Factory
to yourMoshi
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
0.16.6
0.16.5
- Enhancement: Generate manual
Type
construction inmoshi-ir
adapter lookups. Prior to this, we generated IR
code that leveragedtypeOf()
, but this appears to be too late to leverage compiler intrinsics support for it and
appears to cause some issues ifkotlin-reflect
is on the classpath. This should improve runtime performance as a
result.