Firebase dataSnapshot.getValue(Subclass.class) function never returnsHow to store and view images on firebase?Query based on multiple where clauses in FirebaseFirebase: datasnapshot.getValue(className) not workingGet children using orderByChild-equalsTo in Firebase-AndroidAdding Social Media Share Logic From Firebase in AndroidFirebase dataSnapshot.getValue( .class) CrashFirebase datasnapshot.getValue() returns nullUpdated global variables does not reflect inside ValueEventListener's onCancelled methodHow to get the data saved in a USER_ID?Firebase offline sync => can I use condition to sync ? ANDROID
Libertine font numbers have a different height than text
When do you stop "pushing" a book?
How to avoid making self and former employee look bad when reporting on fixing former employee's work?
Is there a need for better software for writers?
Is it a Munchausen Number?
Thawing Glaciers return to hand interaction
I might have messed up in the 'Future Work' section of my thesis
What is the Ancient One's mistake?
Can you turn a recording upside-down?
Has everyone forgotten about wildfire?
Not taking the bishop by the knight, why?
Rusty Chain and back cassette – Replace or Repair?
What is the radius of the circle in this problem?
Is there an idiom that means "revealing a secret unintentionally"?
How does weapons training transfer to empty hand?
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Why did they wait for Quill to arrive?
Are double contractions formal? Eg: "couldn't've" for "could not have"
Using wilcox.test() and t.test() in R yielding different p-values
How is it possible for this circuit to continue functioning correctly?
resoldering copper waste pipe
Why is there a cap on 401k contributions?
Was there a contingency plan in place if Little Boy failed to detonate?
How to handle DM constantly stealing everything from sleeping characters?
Firebase dataSnapshot.getValue(Subclass.class) function never returns
How to store and view images on firebase?Query based on multiple where clauses in FirebaseFirebase: datasnapshot.getValue(className) not workingGet children using orderByChild-equalsTo in Firebase-AndroidAdding Social Media Share Logic From Firebase in AndroidFirebase dataSnapshot.getValue( .class) CrashFirebase datasnapshot.getValue() returns nullUpdated global variables does not reflect inside ValueEventListener's onCancelled methodHow to get the data saved in a USER_ID?Firebase offline sync => can I use condition to sync ? ANDROID
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to obtain value from Firebase for two different children of the "users" that are "sellers" and "customers". Also these children has children that IDs of the sellers or customers.
Seller and Customer are subclasses of the User class and I have implemented all setters and getters. Here is my code that cant obtain value from database:
public class DatabaseWrapper {
private final static DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
private final static DatabaseReference usersRef = ref.child("users");
private final static DatabaseReference productsRef = ref.child("products");
private static Object retrieverObject = null;
public static User getUser(String type, String id) throws InterruptedException
CountDownLatch done = new CountDownLatch(1);
usersRef.child(type).child(id).addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
//Never returns getValue(Subclass.class)
if (type.equals("customers"))
retrieverObject = dataSnapshot.getValue(Customer.class);
else
retrieverObject = dataSnapshot.getValue(Seller.class);
done.countDown();
@Override
public void onCancelled(DatabaseError databaseError)
System.out.println("The read failed: " + databaseError.getCode());
);
done.await();
return (User)retrieverObject;
I deliberately make it sync code to see problem.
If I use getValue(User.class) instead of getValue(Customer.class) and getValue(Seller.class) it works but this usage obviously doesn't obtain fields that are in subclasses.
So the question is how can I retrieve subclass item from Firebase ?
java firebase firebase-realtime-database
add a comment |
I am trying to obtain value from Firebase for two different children of the "users" that are "sellers" and "customers". Also these children has children that IDs of the sellers or customers.
Seller and Customer are subclasses of the User class and I have implemented all setters and getters. Here is my code that cant obtain value from database:
public class DatabaseWrapper {
private final static DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
private final static DatabaseReference usersRef = ref.child("users");
private final static DatabaseReference productsRef = ref.child("products");
private static Object retrieverObject = null;
public static User getUser(String type, String id) throws InterruptedException
CountDownLatch done = new CountDownLatch(1);
usersRef.child(type).child(id).addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
//Never returns getValue(Subclass.class)
if (type.equals("customers"))
retrieverObject = dataSnapshot.getValue(Customer.class);
else
retrieverObject = dataSnapshot.getValue(Seller.class);
done.countDown();
@Override
public void onCancelled(DatabaseError databaseError)
System.out.println("The read failed: " + databaseError.getCode());
);
done.await();
return (User)retrieverObject;
I deliberately make it sync code to see problem.
If I use getValue(User.class) instead of getValue(Customer.class) and getValue(Seller.class) it works but this usage obviously doesn't obtain fields that are in subclasses.
So the question is how can I retrieve subclass item from Firebase ?
java firebase firebase-realtime-database
add a comment |
I am trying to obtain value from Firebase for two different children of the "users" that are "sellers" and "customers". Also these children has children that IDs of the sellers or customers.
Seller and Customer are subclasses of the User class and I have implemented all setters and getters. Here is my code that cant obtain value from database:
public class DatabaseWrapper {
private final static DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
private final static DatabaseReference usersRef = ref.child("users");
private final static DatabaseReference productsRef = ref.child("products");
private static Object retrieverObject = null;
public static User getUser(String type, String id) throws InterruptedException
CountDownLatch done = new CountDownLatch(1);
usersRef.child(type).child(id).addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
//Never returns getValue(Subclass.class)
if (type.equals("customers"))
retrieverObject = dataSnapshot.getValue(Customer.class);
else
retrieverObject = dataSnapshot.getValue(Seller.class);
done.countDown();
@Override
public void onCancelled(DatabaseError databaseError)
System.out.println("The read failed: " + databaseError.getCode());
);
done.await();
return (User)retrieverObject;
I deliberately make it sync code to see problem.
If I use getValue(User.class) instead of getValue(Customer.class) and getValue(Seller.class) it works but this usage obviously doesn't obtain fields that are in subclasses.
So the question is how can I retrieve subclass item from Firebase ?
java firebase firebase-realtime-database
I am trying to obtain value from Firebase for two different children of the "users" that are "sellers" and "customers". Also these children has children that IDs of the sellers or customers.
Seller and Customer are subclasses of the User class and I have implemented all setters and getters. Here is my code that cant obtain value from database:
public class DatabaseWrapper {
private final static DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
private final static DatabaseReference usersRef = ref.child("users");
private final static DatabaseReference productsRef = ref.child("products");
private static Object retrieverObject = null;
public static User getUser(String type, String id) throws InterruptedException
CountDownLatch done = new CountDownLatch(1);
usersRef.child(type).child(id).addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
//Never returns getValue(Subclass.class)
if (type.equals("customers"))
retrieverObject = dataSnapshot.getValue(Customer.class);
else
retrieverObject = dataSnapshot.getValue(Seller.class);
done.countDown();
@Override
public void onCancelled(DatabaseError databaseError)
System.out.println("The read failed: " + databaseError.getCode());
);
done.await();
return (User)retrieverObject;
I deliberately make it sync code to see problem.
If I use getValue(User.class) instead of getValue(Customer.class) and getValue(Seller.class) it works but this usage obviously doesn't obtain fields that are in subclasses.
So the question is how can I retrieve subclass item from Firebase ?
java firebase firebase-realtime-database
java firebase firebase-realtime-database
edited Mar 23 at 14:26
Frank van Puffelen
251k31401428
251k31401428
asked Mar 23 at 8:17
Taha SevimTaha Sevim
33
33
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
[SOLVED]
Who has similar problem that is deserializing objects from Firebase, do not forget to write an empty constructor. I had only constructors with parameters, then I added empty parameter constructor to subclasses, it worked.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311911%2ffirebase-datasnapshot-getvaluesubclass-class-function-never-returns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
[SOLVED]
Who has similar problem that is deserializing objects from Firebase, do not forget to write an empty constructor. I had only constructors with parameters, then I added empty parameter constructor to subclasses, it worked.
add a comment |
[SOLVED]
Who has similar problem that is deserializing objects from Firebase, do not forget to write an empty constructor. I had only constructors with parameters, then I added empty parameter constructor to subclasses, it worked.
add a comment |
[SOLVED]
Who has similar problem that is deserializing objects from Firebase, do not forget to write an empty constructor. I had only constructors with parameters, then I added empty parameter constructor to subclasses, it worked.
[SOLVED]
Who has similar problem that is deserializing objects from Firebase, do not forget to write an empty constructor. I had only constructors with parameters, then I added empty parameter constructor to subclasses, it worked.
answered Mar 23 at 10:03
Taha SevimTaha Sevim
33
33
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311911%2ffirebase-datasnapshot-getvaluesubclass-class-function-never-returns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown