Skip to content

Instantly share code, notes, and snippets.

@GabriellCosta
Last active June 16, 2020 20:59
Show Gist options
  • Save GabriellCosta/db4869b1f8b3ad05bf3e4e3984454372 to your computer and use it in GitHub Desktop.
Save GabriellCosta/db4869b1f8b3ad05bf3e4e3984454372 to your computer and use it in GitHub Desktop.
import com.google.gson.Gson
//Nosso enum para teste
enum class TestEnum {
FIRST,
SECOND
}
//Uma classe contendo uma lista de enums
data class EnumTypeDTO(
val type: List<TestEnum>
)
//Criamos um simples json para validar como sera feita a converção
val api = """
{
type: [first, FIRST]
}
"""
val gson = Gson()
val result = gson.fromJson(api, EnumTypeDTO::class.java)
//Podemos aqui ver o resultado então
println("Enum type: $result")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment