Faisal
Faisal

Reputation: 1472

Firebase complex query from Android results in ERROR

We have a complex data structure stored in Firebase realtime-database and following Firebase's official way of retrieving the data using MVVM + LiveData. We are trying to map the resulting data snapshot(list of users) into a Kotlin data class but results as does not define a no-argument constructor. Complete error below:

  com.google.firebase.database.DatabaseException: Class com.myapp.android.firebase.dto.ProfessionalDetails does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@19.1.0:552)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@19.1.0:545)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.1.0:415)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.1.0:214)
    at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.1.0:79)

The ProfessionalDetails is as below:

@Keep
@IgnoreExtraProperties
data class ProfessionalDetails constructor(
    var bookings: Bookings = Bookings(),
    var business_details: BusinessDetails = BusinessDetails(),
    var clientProvider: String = "",
    var clientUserId: String = "",
    var country: String = "",
    var created: String = "",
    var device_id: String = "",
    var diary: Diary = Diary(),
    var first_name: String = "",
    var hide_profile: String = "",
    var last_name: String = "",
    var mobile_number: String = "",
    var paymentInfoRequired: String,
    var payment_info: PaymentInfo = PaymentInfo("", "", ""),
    var proEmail: String = "",
    var proPwd: String = "",
    var profile_picture: String = "",
    var profile_picture_url: String = "",
    var profile_thumbnail: String = "",
    var profile_thumbnail_url: String = "",
    var service_categories: String = "",
    var services: List<ProfessionalServices> = emptyList(),
    var signup_complete: String = "",
    var signup_step: String = "",
    var terms: String = "",
    var user_type: String = ""
)

As you noticed each element of the data class is initialized as per SOF discussions to overcome the above firebase exception. Had no luck, we suspect disparity in the mapping between the data class and the backend structure.

The suspected areas are pasted below:

Bookings node

and it's equivalent data class is:

@Keep
@IgnoreExtraProperties
data class Bookings constructor(
    var booking_requests: List<BookingRequests> = emptyList()
)

@Keep
data class BookingRequests constructor(
    var date: String = "",
    var payment_currency: String = "",
    var professional_user_id: String = "",
    var service_duration: String = "",
    var service_name: String = "",
    var service_price: String = "",
    var status: String = "",
    var time: String = ""
)

Diary mode

and it's equivalent data class is:

@Keep
@IgnoreExtraProperties
data class Diary constructor(
    var booking_id: String = "",
    var client_first_name: String = "",
    var client_last_name: String = "",
    var client_user_id: String = "",
    var created_by: String = "",
    var date: String = "",
    var duration: String = "",
    var end_time: String = "",
    var payment_currency: String = "",
    var service_name: String = "",
    var service_price: String = "",
    var start_time: String = "",
    var title: String = ""
)

We believe to be a disparity in mapping between data class and database structure, Any lead to convert the dynamic node to data class or suggestions would be highly appreciated.

Thanks in advance for reading such a long write-up.

Upvotes: 0

Views: 84

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

You forgot to provide an initial value for:

var paymentInfoRequired: String,

This prevents Kotlin from creating a no-arg constructor for that data class.

Upvotes: 2

Related Questions