How to map a JSON string to Kotlin Map

No additional library is needed: val jsonObj = JSONObject(jsonString) val map = jsonObj.toMap() where toMap is: fun JSONObject.toMap(): Map<String, *> = keys().asSequence().associateWith { when (val value = this[it]) { is JSONArray -> { val map = (0 until value.length()).associate { Pair(it.toString(), value[it]) } JSONObject(map).toMap().values.toList() } is JSONObject -> value.toMap() JSONObject.NULL -> null else -> value … Read more

How to make sealed classes generic in kotlin?

your Object can’t have a generic type in Kotlin but this could be solved simply by following the example below: sealed class ResponseState<out T> { data object Loading : ResponseState<Nothing>() data class Error(val throwable: Throwable) : ResponseState<Nothing>() data class Success<T>(val item: T) : ResponseState<T>() } writing: val _state = MutableLiveData<ResponseState<MessageModel>>() _state.postValue(ResponseState.Loading) myNetworkCall { response, e … Read more

Generate KDoc for methods in Android Studio [closed]

Since January 2019, there is a plugin on the Jetbrains website called kdoc-generator. https://plugins.jetbrains.com/plugin/10389-kdoc-generator Plugin to generate class and method KDoc. This generator functions exactly like JavaDoc. That means when you create a commentary with “/**” and press enter, the kdoc-generator creates automatically “@param” or “@return” tags for the parameter and return values of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)