Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

com.google.firebase.database.DatabaseException: No properties to serialize found on class java.lang.StringBuilder while saving data to rtdb firebase

I am trying to save the data to realtime database of firebase. But I am getting this error

com.google.firebase.database.DatabaseException: No properties to serialize found on class java.lang.StringBuilder
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(CustomClassMapper.java:548)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(CustomClassMapper.java:330)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(CustomClassMapper.java:167)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(CustomClassMapper.java:142)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(CustomClassMapper.java:61)
at com.google.firebase.database.DatabaseReference.setValueInternal(DatabaseReference.java:282)
at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:159)

I my earlier projects I used the same code but now I am getting this error.

Here is the code of the function that I used for saving the data

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

private fun saveDetails() {

    val userDataRef: DatabaseReference =
        FirebaseDatabase.getInstance().reference.child("UsersData").child(currentUserId)

    val userMap = HashMap<String, Any>()
    userMap["name"] = name
    userMap["email"] = email
    userMap["imageUrl"] = profileImageUrl
    userMap["phoneNumber"] = number

        userDataRef.setValue(userMap).addOnCompleteListener { task ->
            if (task.isSuccessful) {
                Toast.makeText(
                    baseContext,
                    "$name has successfully registered with email id $email.",
                    Toast.LENGTH_SHORT
                ).show()
                startActivity(Intent(this, MainActivity::class.java))
            } else {
                Toast.makeText(baseContext, task.result.toString(), Toast.LENGTH_SHORT).show()
                Log.e("Task  Unsuccessful", task.result.toString())
            }
        }
    }

>Solution :

it seems that Firebase is having trouble serializing one of the values in your userMap. In this case, it’s likely that one of your values is of type java.lang.StringBuilder instead of java.lang.String.

To resolve the issue make sure all the values you put into the userMap are of type String. If any of them are StringBuilder, you should call the toString() method to convert them to a String.

private fun saveDetails() {
    val userDataRef: DatabaseReference =
        FirebaseDatabase.getInstance().reference.child("UsersData").child(currentUserId)

    val userMap = HashMap<String, Any>()
    userMap["name"] = name.toString()
    userMap["email"] = email.toString()
    userMap["imageUrl"] = profileImageUrl.toString()
    userMap["phoneNumber"] = number.toString()

    userDataRef.setValue(userMap).addOnCompleteListener { task ->
        if (task.isSuccessful) {
            Toast.makeText(
                baseContext,
                "$name has successfully registered with email id $email.",
                Toast.LENGTH_SHORT
            ).show()
            startActivity(Intent(this, MainActivity::class.java))
        } else {
            Toast.makeText(baseContext, task.result.toString(), Toast.LENGTH_SHORT).show()
            Log.e("Task  Unsuccessful", task.result.toString())
        }
    }
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading