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;








0















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 ?










share|improve this question






























    0















    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 ?










    share|improve this question


























      0












      0








      0








      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 ?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 14:26









      Frank van Puffelen

      251k31401428




      251k31401428










      asked Mar 23 at 8:17









      Taha SevimTaha Sevim

      33




      33






















          1 Answer
          1






          active

          oldest

          votes


















          0














          [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.






          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            [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.






            share|improve this answer



























              0














              [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.






              share|improve this answer

























                0












                0








                0







                [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.






                share|improve this answer













                [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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 23 at 10:03









                Taha SevimTaha Sevim

                33




                33





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해