title: Java Get Value from Object by Key Name
body: <p>I have retrieved an object from Firebase and would like to access the values of it using the name of each field I would like the value for.  In javascript, this would be something as simple as <code>myObject.name</code> to retrieve the name in the object.</p>
  
  <p>How can I do the equivalent in Java?</p>
  
  <pre class="lang-java prettyprint-override"><code>mDatabase = FirebaseDatabase.getInstance().getReference();
  user = FirebaseAuth.getInstance().getCurrentUser();
  userId = user.getUid();
  
  ValueEventListener myObjectListener = new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
          Log.i(TAG, "getting data");
          Object myObject = dataSnapshot.getValue();
  
          Log.v(TAG, myObject.toString()); 
          // Outputs: {name= "john doe", hair="brown", isStudent=true, age=12} 
  
          // HERE is where I would like to get the name.
          // DOES NOT work. Have also attempted things like
          // myObject.getString("name"), etc.
          myObject.getClass().getFieldName("name") 
      }
      @Override
      public void onCancelled(DatabaseError databaseError) {
          Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
      }
  };
  
  mDatabase.child("users").child(userId).addValueEventListener(myObjectListener);
  </code></pre>