JsonClass

Customizes how a type is encoded as JSON.

@Retention(value = )
annotation class JsonClass

Functions

annotationType
Link copied to clipboard
abstract fun annotationType(): Class<out Annotation>
equals
Link copied to clipboard
abstract fun equals(p: Any): Boolean
generateAdapter
Link copied to clipboard

True to trigger the annotation processor to generate an adapter for this type.

There are currently some restrictions on which types that can be used with generated adapters:

  • The class must be implemented in Kotlin (unless using a custom generator, see ).
  • The class may not be an abstract class, an inner class, or a local class.
  • All superclasses must be implemented in Kotlin.
  • All properties must be public, protected, or internal.
  • All properties must be either non-transient or have a default value.

abstract fun generateAdapter(): Boolean
generator
Link copied to clipboard

An optional custom generator tag used to indicate which generator should be used. If empty, Moshi's annotation processor will generate an adapter for the annotated type. If not empty, Moshi's processor will skip it and defer to a custom generator. This can be used to allow other custom code generation tools to run and still allow Moshi to read their generated JsonAdapter outputs.

Requirements for generated adapter class signatures:

  • The generated adapter must subclass JsonAdapter and be parameterized by this type.
  • should be used for the fully qualified class name in order for Moshi to correctly resolve and load the generated JsonAdapter.
  • The first parameter must be a Moshi instance.
  • If generic, a second Type[] parameter should be declared to accept type arguments.

Example for a class "CustomType":

{@code * class CustomTypeJsonAdapter(moshi: Moshi, types: Array) : JsonAdapter

To help ensure your own generator meets requirements above, you can use Moshi’s built-in generator to create the API signature to get started, then make your own generator match that expected signature.

abstract fun generator(): String
hashCode
Link copied to clipboard
abstract fun hashCode(): Int
toString
Link copied to clipboard
abstract fun toString(): String