Open sulemankhan4 opened 2 years ago
you cannot update a mutable list in your class, whether its a data class or not. changing the list updates the list reference that is already bound to your model
you cannot update a mutable list in your class, whether its a data class or not. changing the list updates the list reference that is already bound to your model
but im creating a copy using gson, and why exception arises when using data class and not in using normal class
I have a data class
var homeList = ArrayList()
Basically for a specific index, im updating data List , using below code.
val brandDataList = HomeRepository.fetchShopByBrandData(urlParams) val newHomeDataList = newHomeDataModelLiveData.value val shopByBrandItem = Gson().fromJson(
Gson().toJson(newHomeDataList?.get(position)), NewHomeDataModel::class.java)
val chipList = shopByBrandItem?.chipList?: ArrayList()
for ((index, chip) in chipList.withIndex()) {
chip.selected = if (index == chipIndex) 1 else 0
chipList[index] = chip
}
chipList[chipIndex].isApiCallDone = brandDataList?.size ?: 0 > 0
chipList[chipIndex].dataList = brandDataList
shopByBrandItem.chipList = chipList
newHomeDataList?.set(position, shopByBrandItem)
newHomeDataList?.let {
newHomeDataModelLiveData.postValue(it)
}