Enum Json Adapter
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:
Moshi moshi = new Moshi.Builder()
.add(CurrencyCode.class, EnumJsonAdapter.create(CurrencyCode.class)
.withUnknownFallback(CurrencyCode.USD))
.build();
Functions
fail On Unknown
Link copied to clipboard
from Json Value
Link copied to clipboard
serialize Nulls
Link copied to clipboard
to Json Value
Link copied to clipboard
with Unknown Fallback
Link copied to clipboard
open fun withUnknownFallback(@Nullable fallbackValue: T): EnumJsonAdapter<T>
Content copied to clipboard
Create a new adapter for this enum with a fallback value to use when the JSON string does not match any of the enum's constants.