Search code examples
androidkotlinfirebase-realtime-databasepojodata-class

Best practices to convert Firebase database having dynamic values to kotlin data classes


My firebase realtime database has dynamic values for nodes(under services such as Beard - Trim, Facial, Hair coloring etc.).

What would be the best practices to convert it to Kotlin data class(Java POJO)?


data class User constructor(
    var services: List<Services>
)

data class Services constructor(
    var description: String = "",
    var duration: String = "",
    var name: String = "",
    var picture: String = "",
    var picture_url: String = "",
    var price: String = "",
    var thumbnail: String = "",
    var thumbnail_url: String = ""
)

Solution

  • Finally, solved the issue with Map (instead of List) as the data receives from the Firebase as Map.

    var services: Map<String, Services> 
    

    Folks, thank you all for support.