Isn't it possible to send it as an object when transferring Firebase DB?

Asked 2 years ago, Updated 2 years ago, 65 views

Pass the following types corresponding to the available JSON types: String Long Double Boolean Map List Pass custom Java objects. The class that defines the object must have a default constructor that does not take arguments and a public getter for the property you want to specify.

public class User {

    public String username;
    public String email;

    public User() {
        // // Default constructor required for calls to DataSnapshot.getValue(User.class)
    }

    public User(String username, String email) {
        this.username = username;
        this.email = email;
    }
}
private void writeNewUser(String userId, String name, String email) {
    User user = new User(name, email);

    mDatabase.child("users").child(userId).setValue(user);
}

It is explained in the Firebase document, but if you write the same as above, there will be an error.

Caused by: com.google.firebase.database.DatabaseException: Found conflicting getters for name: isChangingConfigurations Like this Just in case, you can't put a getter setter in the User object What's wrong?

android firebase database

2022-09-22 20:38

1 Answers

The stack trace refers to isChangingConfigurations, which is the name of a method of Activity. This probably indicates that you have declared class Person as an inner class of an activity. When Firebase serializes Person it also tries to serialize the enclosing Activity class and fails.

Move the declaration of Person to package level or change the declaration to make it a static inner class: public static class Person.


2022-09-22 20:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.