I have a list of custom objects that I want to parse and save in shared prefs.
internal fun putObjects(key: String, item: List<Any>) {
val listJson = toJson(item)
edit { it.putString(key, listJson) }
}
internal fun <T> getObjects(key: String): List<Any> {
val json = prefs.getString(key, "") ?: ""
val objectList: List<Any>? = fromJson(json)
return objectList ?: listOf()
}
Moshi builder is created like this:
return Moshi.Builder()
...
.addLast(KotlinJsonAdapterFactory())
.build()
Expected result is ArrayList<XObject>
, but instead Moshi returns ArrayList<LinkedHashTreeMap<String, String>>
.