Hi, I want to map an enum class like `enum class S...
# announcements
s
Hi, I want to map an enum class like
enum class Status { OK, FAILED }
to a JSON response (with Moshi). Unfortunately the JSON values are written in lower case like “ok” or “failed” and it’s not possible to overwrite the enum classes’ values. Any chances this is somehow possible or do I have to write a custom Moshi adapter?
j
You should be able to use the
@Json
annotation: https://github.com/square/moshi#custom-field-names-with-json
However you need to include the moshi-kotlin library to make them work: https://github.com/square/moshi#kotlin-support
s
@jmesserli
@Json
on each enum value (like
enum class Status { @Json(name = "ok") OK }
works! :) Thanks!