Extensions for Moshi including IR plugins, moshi-sealed, and more.
APACHE-2.0 License
Bot releases are hidden (Show)
1.5.0
.1.5.0
upgrade.1.8.0
.1.5.0-1.0.0-alpha10
.SymbolProcessorProvider
APIs.Sequence
-based KSP APIs where possible.0.3.0
.typealias
'd.@JsonQualifier
annotations.@JsonQualifier
annotations.moshi-adapters
an api
dependency in moshi-sealed-runtime
RecordsJsonAdapterFactory
is no longer in preview and now built against JDK 16.final record Message(String value) {
}
public static void main(String[] args) {
Moshi moshi = new Moshi.Builder()
.add(new RecordsJsonAdapterFactory())
.build();
JsonAdapter<Message> messageAdapter = moshi.adapter(Message.class);
}
JavaSealedJsonAdapterFactory
is now built against JDK 16. Note this feature is still in preview.Thanks to the following contributors for contributing to this release! @remcomokveld, @martinbonnin, and @eneim
1.4.30-1.0.0-alpha04
in KSP-using libraries. Among other changes, these processors now run allKspLogger.error()
API now.New: Experimental support for Java record
classes via new moshi-records-reflect
artifact. See
RecordsJsonAdapterFactory
. Requires JDK 15 + --enable-preview
.
Moshi moshi = new Moshi.Builder()
.add(new RecordsJsonAdapterFactory())
.build();
final record Message(String value) {
}
New: Experimental support for Java sealed
classes and interfaces in moshi-sealed via new
moshi-sealed-java-sealed-reflect
artifact. See JavaSealedJsonAdapterFactory
. Requires JDK 15 + --enable-preview
.
Moshi moshi = new Moshi.Builder()
.add(new JavaSealedJsonAdapterFactory())
.add(new RecordsJsonAdapterFactory())
.build();
@JsonClass(generateAdapter = true, generator = "sealed:type")
sealed interface MessageInterface
permits MessageInterface.Success, MessageInterface.Error {
@TypeLabel(label = "success", alternateLabels = {"successful"})
final record Success(String value) implements MessageInterface {
}
@TypeLabel(label = "error")
final record Error(Map<String, Object> error_logs) implements MessageInterface {
}
}
New: @AdaptedBy
annotation support in moshi-adapters
. This is analogous to Gson's @JsonAdapter
annotation,
allowing you to annotate a class or a property with it to indicate which JsonAdapter
or JsonAdapter.Factory
should be used to encode it.
val moshi = Moshi.Builder()
.add(AdaptedBy.Factory())
.build()
@AdaptedBy(StringAliasAdapter::class)
data class StringAlias(val value: String)
class StringAliasAdapter : JsonAdapter<StringAlias>() {
override fun fromJson(reader: JsonReader): StringAlias? {
return StringAlias(reader.nextString())
}
override fun toJson(writer: JsonWriter, value: StringAlias?) {
if (value == null) {
writer.nullValue()
return
}
writer.value(value.value)
}
}