<@U589QURRQ> for example i’ll take SerializedName ...
# reflect
a
@diesieben07 for example i’ll take SerializedName from Gson pakkage
Copy code
package org.example

import com.google.gson.annotations.SerializedName

import java.util.HashMap
import kotlin.reflect.full.declaredMemberProperties

class Example {
    @SerializedName("some_var")
    var someVar: String? = ""
    @SerializedName("another_var")
    var anotherVar: Int? = 1

    fun toHashMap(): HashMap<String, Any?> {
        return this::class.declaredMemberProperties.mapNotNull { field ->
            if (field.annotations.any { it is SerializedName} ) {
                field.annotations.find { it is SerializedName }?.let {
                    field.name to (it as SerializedName).value
                }
            } else null
        }.toMap(HashMap())
    }
}