EnumJsonAdapter

class EnumJsonAdapter<T : Enum<T>?> : JsonAdapter<T>

A JsonAdapter for enums that allows having a fallback enum value when a deserialized string does not match any enum value. To use, add this as an adapter for your enum type on your Moshi.Builder:

{@code * Moshi moshi = new Moshi.Builder() * .add(CurrencyCode.class, EnumJsonAdapter.create(CurrencyCode.class) * .withUnknownFallback(CurrencyCode.USD)) * .build(); * }

Functions

create
Link copied to clipboard
open fun <T : Enum<T>?> create(enumType: Class<T>): EnumJsonAdapter<T>
failOnUnknown
Link copied to clipboard
fun failOnUnknown(): JsonAdapter<T>
fromJson
Link copied to clipboard
open fun fromJson(reader: JsonReader): T
abstract fun fromJson(p: JsonReader): T
fromJsonValue
Link copied to clipboard
fun fromJsonValue(value: Any): T
indent
Link copied to clipboard
open fun indent(indent: String): JsonAdapter<T>
lenient
Link copied to clipboard
fun lenient(): JsonAdapter<T>
nonNull
Link copied to clipboard
fun nonNull(): JsonAdapter<T>
nullSafe
Link copied to clipboard
fun nullSafe(): JsonAdapter<T>
serializeNulls
Link copied to clipboard
fun serializeNulls(): JsonAdapter<T>
toJson
Link copied to clipboard
fun toJson(value: T): String
open fun toJson(writer: JsonWriter, value: T)
abstract fun toJson(p: JsonWriter, p1: T)
toJsonValue
Link copied to clipboard
fun toJsonValue(value: T): Any
toString
Link copied to clipboard
open fun toString(): String
withUnknownFallback
Link copied to clipboard
open fun withUnknownFallback(@Nullable() fallbackValue: T): EnumJsonAdapter<T>
Create a new adapter for this enum with a fallback value to use when the JSON string does notmatch any of the enum's constants.