Reputation: 29
The above error is showing when I want to open the app on my mobile phone. But it works normally on emulator.
The model class is:
data class Product(
var charge: List<String>? = emptyList(),
var description: String? = "",
var id: String? = "",
var image: List<String>? = emptyList(),
var name: String? = "",
var priceA: List<String>? = emptyList(),
var priceD: List<String>? = emptyList(),
var quantity: List<String>? = emptyList(),
var size: List<String>? = emptyList(),
var tag: List<String>? = emptyList()
) : Parcelable
Data retrieving code from Firestore DataBase :
db.addSnapshotListener { snapshot, e->
if(e!=null){
return@addSnapshotListener
}
productList = snapshot!!.toObjects(Product::class.java)
adapter = Adapter(productList, this@HomeActivity, ProductInterface::class.java)
fireStoreList.adapter = adapter
fireStoreList.setHasFixedSize(true)
fireStoreList.layoutManager = GridLayoutManager(this@HomeActivity, 2)
hideProgress()
}
structure of data in Firestore Database:
Logcat :
2021-04-08 22:50:21.404 7509-7509/com.example.modshabuisness E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.modshabuisness, PID: 7509 java.lang.RuntimeException: Could not deserialize object. Expected a List, but got a class java.lang.String (found in field 'image') at com.google.firebase.firestore.util.CustomClassMapper.deserializeError(CustomClassMapper.java:563) at com.google.firebase.firestore.util.CustomClassMapper.deserializeToParameterizedType(CustomClassMapper.java:276) at com.google.firebase.firestore.util.CustomClassMapper.deserializeToType(CustomClassMapper.java:187) at com.google.firebase.firestore.util.CustomClassMapper.access$300(CustomClassMapper.java:54) at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:770) at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:741) at com.google.firebase.firestore.util.CustomClassMapper.convertBean(CustomClassMapper.java:542) at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(CustomClassMapper.java:253) at com.google.firebase.firestore.util.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:100) at com.google.firebase.firestore.DocumentSnapshot.toObject(DocumentSnapshot.java:183) at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(QueryDocumentSnapshot.java:116) at com.google.firebase.firestore.QuerySnapshot.toObjects(QuerySnapshot.java:184) at com.google.firebase.firestore.QuerySnapshot.toObjects(QuerySnapshot.java:166) at com.example.modshabuisness.activity.HomeActivity$onCreate$3.onEvent(HomeActivity.kt:93) at com.example.modshabuisness.activity.HomeActivity$onCreate$3.onEvent(HomeActivity.kt:37) at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(Query.java:1133) at com.google.firebase.firestore.Query$$Lambda$3.onEvent(Unknown Source:6) at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(AsyncEventListener.java:42) at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(Unknown Source:6) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:255) at android.app.ActivityThread.main(ActivityThread.java:8214) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Upvotes: 2
Views: 910
Reputation: 713
It seems that when you have more than one Image it response as a List of Images but somehow when you have only one Image it response it as a String thats why you have deserialization error. Unfortunately, the deserializer cannot put a String to a List of Strings
Upvotes: 1