bigbone icon indicating copy to clipboard operation
bigbone copied to clipboard

Try to reuse apiName function for serializable enum classes

Open PattaFeuFeu opened this issue 6 months ago • 2 comments

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.

PattaFeuFeu avatar Dec 28 '23 17:12 PattaFeuFeu