https://kotlinlang.org logo
Title
s

svenjacobs

09/20/2017, 7:59 AM
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

jmesserli

09/20/2017, 8:04 AM
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

svenjacobs

09/20/2017, 8:13 AM
@jmesserli
@Json
on each enum value (like
enum class Status { @Json(name = "ok") OK }
works! :) Thanks!