파이어베이스 DB 전송할 때 객체로도 전송이 가능하지 않나요?

조회수 1587회

사용 가능한 JSON 유형에 해당하는 다음과 같은 유형을 전달합니다. String Long Double Boolean Map List 맞춤 Java 개체를 전달합니다. 개체를 정의하는 클래스에는 인수를 취하지 않는 기본 생성자 및 지정할 속성에 대한 공개 getter가 있어야 합니다.

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);
}

라고 파이어베이스 문서에서 설명하고 있는데 위와 같이 똑같이 해서 써보면 에러가 납니다

Caused by: com.google.firebase.database.DatabaseException: Found conflicting getters for name: isChangingConfigurations 요렇게요 혹시나 해서 User객체에 게터 세터 넣어봐도 안되구요 머가 잘못된걸까요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • 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.

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)