Android Kotlin firebase.database.DatabaseException: No properties to serialize found on class

前端 未结 3 1931
北荒
北荒 2020-12-22 13:44

I have followed the advice of other SO solution: 1. Make my class Serializeable 2. Have a default constructor for Firebase 3. Update my proguard rules (Not sure about this o

相关标签:
3条回答
  • 2020-12-22 14:00

    Solved, even in Kotlin it seems the variables had to be explicitly Public.

    import java.io.Serializable
    
    /**
     * Created by fyi2 on 2/21/18.
     */
    class User :Serializable {
        public var displayName:String=""
        public var email:String=""
        public  var photoUrl:String=""
        public var userId:String=""
    
        constructor() {}
    
        constructor(displayName: String, email: String, photoUrl: String, userId: String) {
            this.displayName = displayName
            this.email = email
            this.photoUrl = photoUrl
            this.userId = userId
        }
    
    }
    

    Once that was modified, the rest worked as is.

    0 讨论(0)
  • 2020-12-22 14:02

    you can easily use a data class, it already comes with an empty constructor ect.

    @IgnoreExtraProperties
    data class User(
        var displayName: String? = null,
        var email: String? = null,
        var photoUrl : String? = null,
        var userId: String? = null
    )
    
    0 讨论(0)
  • 2020-12-22 14:16

    If you got the issue on release apk then Do like this in your proguard file

        -keepattributes Signature
    
        -keepclassmembers class com.yourcompany.models.** {
          *;
        }
    
    0 讨论(0)
提交回复
热议问题