Created
January 19, 2017 09:44
-
-
Save shiraji/2d50f87374ed3c28141b2e7acbba932d to your computer and use it in GitHub Desktop.
Android-Orma EnumAdapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@StaticTypeAdapter(targetType = Enum::class, serializedType = String::class) | |
class EnumAdapter { | |
companion object { | |
@JvmStatic | |
fun <T : Enum<T>> serialize(source: T): String { | |
return source.name | |
} | |
@JvmStatic | |
fun <T : Enum<T>> deserialize(serialized: String, type: Class<T>): T { | |
return type.enumConstants.first { it.name == serialized } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment