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

JTable: display strings with newline characters as multiple lines
Regex: Performing string replacement with same pattern but with different replacement words
Java HTTPS client certificate authentication with store Local Store Certificate
Liberty profile server [closed]
Hiding Legend for Zero Value Chart Items javaFX
.class exception when calling a method
Java - determining is Poker Hand has a Pair
Redirect between two application roots - Jersey
How does the JVM execute a servlet compared with a regular Java class?
Apply / merge image difference to another image?
setOnClickListener shows error
Why my maven get so many red wave lines below their dependencies?
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
Automating the Trading Web Application using Selenium
Remove decimal ending zeros from BigDecimal
LibGdx collision detection between sprites?

Categories

HOME
client
bluetooth
hook
gerrit
cplex
react-router
kalman-filter
adb
getelementsbytagname
c#-2.0
flyway4
wheelnav.js
dax
vb.net-2010
usergrid
commonmark
dtrace
jsprit
reactive-cocoa
jtextfield
jasonette
tar
vlsi
compatibility
vision
quote
lightswitch-2013
socialengine
media-queries
galsim
code-contracts
commit
android-kernel
picasso
neuroscience
libvpx
sharefile
impersonation
android-fingerprint-api
lumberjack
reportingservices-2005
turbogears
outlook-api
acoustics
wptoolkit
galleria
angular-resource
kbuild
akka-cluster
pdfclown
spring-mongodb
sonarlint-vs
query-performance
eventkit
google-cdn
parallel-data-warehouse
setuptools
grails-tomcat-plugin
savon
ado.net-entity-data-model
rtbkit
vhd
spidermonkey
processmodel
nsight
sniffer
c++03
csquery
tween
clicktag
websocket4net
htmlcleaner
poller
dealloc
datagridviewcolumn
html5-notifications
xsockets.net
aqtime
ruby-datamapper
plasma
android-hardware
anonymous-methods
mt
regsvr32
mod-auth
xmemcached
calling-convention
celltable
datareader
w3wp.exe
gamma
rescale
ncqrs
adrotator
avatar
mediarss
genealogy
windows-live-messenger

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