Firebase - realtime database set additional value to user throws exception

狂风中的少年 提交于 2019-12-24 16:42:37

问题


I have class User which has additional info, but it is throwing:

com.google.firebase.database.DatabaseException: Serializing Collections is not supported, please use Lists instead

My code is:

User user = new User(Gender.valueOf(mGenderSpinner.getSelectedItem().toString()));
                            Log.d("GENDER", user.getGender().toString());
                            mFirebaseDatabase.getReference("Users")
                                    .child(mAuth.getCurrentUser().getUid())
                                    .setValue(user)

The question is how I can still set User.class value or this is not possible?


回答1:


Value type ordering

  • Null values
  • Boolean values
  • Integer and floating-point values, sorted in numerical order
  • Date values
  • Text string values
  • Byte values
  • Cloud Firestore references
  • Geographical point values
  • Array values
  • Map values

com.google.firebase.database.DatabaseException: Serializing Collections is not supported, please use Lists instead

  • Above Exception show that you have unsupported Collections object on User class just change with one of above supported type ex. List<Type>.

Update

Thanks to Alex Mano comment,

  • Above is Data Types is for Firebase Cloud Database, But Firebase Realtime Database as following.

  • Pass types that correspond to the available JSON types as follows:

    • String
    • Long
    • Double
    • Boolean
    • Map
    • List


来源:https://stackoverflow.com/questions/51813160/firebase-realtime-database-set-additional-value-to-user-throws-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!