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();
Content copied to clipboard
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
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.