java


Crashing on deserializing list from Firebase


I have a model which contains a list.
class Group {
List<String> members;
// Other fields
}
I'm inserting the whole model in Firebase using databaseRef.setValue(group). Now it's being inserted properly in firebase but the problem arise when I try to add any new value in members field.
I'm using membersRef.push().setValue("newMember#gmail.com") to add new field in members list on firebase.
When Group object was created initially Firebase used "0", "1", etc as key but when I push() it creates a unique String as key.
I'm creating the Java object back using this code:
groupReference.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Group group = dataSnapshot.getValue(Group.class);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
Now the problem is when creating the Group class back from Firebase it tries to convert the members field in a List because it's key start from 0 but after some iteration there is a String key (something like "-KjTzYGRDZN99rBZfPDF") so it crashes trying to convert it to List.
My Firebase object looks something like this:
Group
|-----members
|----0: "abc#gmail.com"
|-----KjTzYGRDZN99rBZfPDF: "def#gmail.com"
I'm confused how do I solve this problem. How do I tell firebase to use unique key for List instead of 0, 1, 2, etc?
use a HashMap instead of List. then when storing the group object on firebase, make sure the hashmap is empty. Now, you can migrate to the membersRef and put all the values you want using a loop with push() and setValue() in subsequent code.

Related Links

Android - Pass value from app to webview page not working
Java create instance with deep empty objects
Writing and accessing JSON file saved to internal memory
How to decode to UTF-8 String from Hex encoded string
Hibernate - What primary key should I use in a one to many relationship without an ID on the child table
Spring not able to load class from ApplicationContext xml file
How to install jdk7 on CentOS?
Regex Junit Test
No Class Def Found Error java Android activity testing
Tomcat Apache 6 server on Eclipse Error
Extract words in rectangles from text
libGDX - Using a HashMap causes growing HeapSize and Out of Memory on Android Phone
Reloading of the js scripts via jquery load /ajax
How many Number of objects Created
how can i Merge files
Java KeyListener not works

Categories

HOME
log4j
clips
push-notification
layout
office365api
read-eval-print-loop
malloc
onelogin
upload
portia
append
vault
nano-server
vb.net-2010
circuit
carthage
tostring
finite-automata
angular-ui
interop
alpine
swiftlint
orleans
cloudhub
css-animations
accessor
autosys
qhull
selectedindexchanged
wpfdatagrid
neo4j-spatial
ecto
winrt-xaml-toolkit
column-family
framemaker
phpfreechat
normal-distribution
jmonkeyengine
wixsharp
http-digest
overlap
dosbox
jquery-bootgrid
automake
abstract-class
lumberjack
node-gyp
nomethoderror
long-polling
youcompleteme
dotnetzip
gabor-filter
lowpass-filter
python-cryptography
firmata
azure-sdk
android-textview
trash
qgraphicsview
python-stackless
bluemix-app-scan
pagerank
tcpserver
execute
riak-cs
ionic
microbenchmark
camanjs
wp-query
system.net.webexception
concurrent-collections
stxxl
commoncrypto
quartz-graphics
flash-builder4.5
padarn
jquery-knob
isnullorempty
errai
online-compilation
qt-jambi
heartbeat
coercion
file-comparison
lang
visitor-statistic
sproutcore-2
filtered-index
javap
grid-system
dbisam

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App