bigbone
bigbone copied to clipboard
Try to reuse apiName function for serializable enum classes
At some point, we introduced the apiName
function on some enum classes where the serializable name that is expected by the Mastodon API contains characters we cannot recreate in enum class names (such as posting:default:visibility
) and thus cannot easily get the name of those classes by just getting its name.toLowercase()
.
The current approach is as such:
@Serializable
enum class NotificationType {
[…]
@SerialName("update")
UPDATE;
@OptIn(ExperimentalSerializationApi::class)
val apiName: String get() = serializer().descriptor.getElementName(ordinal)
}
That approach works well but we need to add those exact lines for every enum class
where we want that apiName
function.
When implementing a solution for this ticket it would be good if we could reuse the same e.g. extension function so that all enum classes (or at least those enum classes that have the @Serializable
annotation and thus a serializer()
to begin with) automatically.