2017-11-10 3 views
2

배열이 포함 된 Firestore 문서를 가져 오려고하는데 배열을 추가하자마자 DocumentSnapshot.toObject 메서드를 제대로 작동시키지 못합니다. 배열에 최대 1-2 개의 항목까지만 포함 할 수 있으므로 컬렉션을 사용하고 싶지 않습니다.배열을 포함하는 Firestore 문서를 비 직렬화하는 권장 방법은 무엇입니까?

java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type com.google.android.gms.internal.zzegf to DocumentReference (found in field 'references.[0]') 

다음은

data class SomeModel(
     var references : ArrayList<DocumentReference> = ArrayList(0), 
     var title : String? = null, 
     var acronym : String? = null, 
     var number : Long? = null 
){ 

} 

내 경우 FireStore 문서를 하나 DocumentReference으로 references라는 이름의 배열을 포함 내 모델 클래스입니다. 모델 클래스에서 참조 필드를 제거하면 객체가 비 직렬화됩니다.

답변

0

firebase-firestore의 내 gradle 파일 항목을 11.4.2에서 11.6.0으로 업데이트하면 직렬화 문제가 해결되었습니다.

0

내가 하나의 문서 내에서 항목의 목록을 검색하려면 내가 할 수 : - : 내가 기본 제공 -

문자열의 목록이 포함 된 데이터 클래스는 목록

참고 모든 유형을 수 deserialize를 위해 모든 매개 변수에 대한 값이 필요합니다. 클래스에는 빈 계약자가 있습니다. 경우 FireStore 데이터베이스에

val db = FirebaseFirestore.getInstance() 
    val someModelRef = db.collection("someCollection").document("SomeModel") 
    someModelRef.get().addOnSuccessListener { 
     val someModel : SomeModel = it.toObject(SomeModel::class.java) 

     someModel.references.forEach { 
      Log.i("MainActivity","items $it") 
     } 

    } 

데이터 : - - :

data class SomeModel(val references : List<String> = emptyList() , val title : String = "" , val acronym : String = "" , val number : Long = 0L) 

는 내가 문서의 항목을 이용하여 목록을 포함하여이 방법이 하나의 문서에 포인트를 역 직렬화 할 수

enter image description here

위 코드를 실행하면 내 logcat에 출력됩니다.

enter image description here

+0

오른쪽이지만 문자열 목록 대신 다른 문서에 대한 Firebase DocumentReferences의 배열입니다. List 및 emptyList를 사용해 보겠습니다. – John

관련 문제