android - firebase database reading nested list error -
i trying read following data structure
{ "posts" : { "-kropyvvmlkrxjix1fhd" : { "appliedusers" : { "flaged" : false, "latitude" : 0, "longitude" : 0, "noflags" : 0, "noposts" : 0, "rating" : 0 }, "salary" : "5454564", "title" : "زسروس", } }, "users" : { "########" : { "birthdate" : "8-18-1995", "flaged" : false, "image" : "https://scontent.xx.fbcdn.net/v/t1.0-1/p100x100/11018975_10153075514031013_8079824273778693128_n.jpg?oh=7d4a511abf155a65cda6dde4bfe7b180&oe=59f52e95", "latitude" : 30.784419, "longitude" : 30.987274, "name" : "aya mohamed hamed", "noflags" : 0, "noposts" : 0, "rating" : 0, "uid" : "########", "userphone" : "01007211319" } } }
using following pojo
public class job { public map<string, user> appliedusers = new hashmap<>(); private string title; private string salary; // empty public constructor // constructor // public getters , setters per each property
and user pojo class
public class user { private string uid; private string image; private string name; private string birthdate; private string userphone; private long rating; private int noposts; private int noflags; private string address; private double longitude; private double latitude; private boolean isflaged; // empty public constructor // constructor // public getters , setters per each property}
my read jobs function is:
public static void getalljobs(jobsdatachangelistener jobsdatachangelistener) { postsdbref = firebasedatabase.getinstance().getreference("posts"); postsdbref.addchildeventlistener(new childeventlistener() { @override public void onchildadded(datasnapshot datasnapshot, string s) { arraylist<job> jobs = new arraylist<>(); logging.log(""+datasnapshot.getvalue()); job job = datasnapshot.getvalue(job.class); jobs.add(job); jobsdatachangelistener.onjobsdatachange(jobs, 1); } @override public void onchildchanged(datasnapshot datasnapshot, string s) { } @override public void onchildremoved(datasnapshot datasnapshot) { } @override public void onchildmoved(datasnapshot datasnapshot, string s) { } @override public void oncancelled(databaseerror databaseerror) { log.i(getclass().getname().tostring(), ": " + databaseerror.getmessage()); } }); }
the function retrieving posts fine until inserted applied users map pojo object, each time try read jobs/posts, following issue
com.google.firebase.database.databaseexception: can't convert object of type java.lang.long type com.jobease.www.jobease.models.user
the data under appliedusers
not match definition in code.
appliedusers flaged: false latitude: 0
in code you're mapping to:
public map<string, user> appliedusers = new hashmap<>();
you didn't share definition of user
, seems unlikely it's type allows both boolean
(for flaged
) , number (for latitude
).
when you're trying read job, client throws error because can't convert 0
user
object.
update
if have under appliedusers
single user, definition should be:
public class job { public user appliedusers; private string title; private string salary; ...
Comments
Post a Comment