title: java.lang.ClassCastException: java.util.HashMap cannot be cast to custom data class
body: <p>I upload my data class object to Firestore, it uploads fine, when I try to download it from another activity the <code>java.lang.ClassCastException</code> occurs.
  I need the object of Cart class in AddToCart.java to be saved in the Firestore (Success) and get it back in Cart.java (Failure). PLEASE HELP!!!!!</p>
  
  <p>Here is the how I am putting data into the Firestore:</p>
  
  <pre><code> private void updateFirestore() {
  
      Map cartList = new HashMap&lt;String,CartModel&gt;();
  
      //I put data into the map
  
      FirebaseFirestore firestoreRef = FirebaseFirestore.getInstance();
      firestoreRef.collection(colloctionKeyTitle)
                    .document(currentSelectedModel.getUserId()).set(cartList)
  </code></pre>
  
  <p>Here, the map with one key value is uploaded to firestore:
  <img src="https://i.imgur.com/TK0M4oV.png" alt="Firestore image" title="Firestore"></p>
  
  <p>NOW, here is the code to get this map back.</p>
  
  <pre><code> FirebaseFirestore firestoreRef = FirebaseFirestore.getInstance();
  
      Task&lt;DocumentSnapshot&gt; documentSnapshot = firestoreRef.collection(COLLECTION_ID).document(userId).get()
              .addOnCompleteListener(new OnCompleteListener&lt;DocumentSnapshot&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;DocumentSnapshot&gt; task) {
                      cartList = task.getResult().getData();
                      if (cartList != null) {
                          if (!cartList.isEmpty()) {
                              for (String key : cartList.keySet()) {
                                  Object object = cartList.get(key);// In object variable I see my data when debug, but app crashes on next line.
                                  Constant.listCartItems.add((CartModel) object); //this is the line where error occur.
                              }
                          }
  
                      }
                  }
              });
  </code></pre>
  
  <p>Here is my CartModel.java (Data class)</p>
  
  <pre><code>public class CartModel {
  private String productTitle,productPrice, featuredImagePath, quantity;
  
  public CartModel(String productTitle, String productPrice, String featuredImagePath,String quantity) {
      this.productTitle = productTitle;
      this.productPrice = productPrice;
      this.quantity=quantity;
      this.featuredImagePath = featuredImagePath;
  }
  
  public CartModel(String productTitle, String productPrice, String featuredImagePath) {
      this.productTitle = productTitle;
      this.productPrice = productPrice;
      this.featuredImagePath = featuredImagePath;
  }
  
  public CartModel() {
  
  }
  
  
  public String getQuantity() {
      return quantity;
  }
  
  public void setQuantity(String quantity) {
      this.quantity = quantity;
  }
  
  public String getProductTitle() {
      return productTitle;
  }
  
  public void setProductTitle(String productTitle) {
      this.productTitle = productTitle;
  }
  
  public String getProductPrice() {
      return productPrice;
  }
  
  public void setProductPrice(String productPrice) {
      this.productPrice = productPrice;
  }
  
  public String getFeaturedImagePath() {
      return featuredImagePath;
  }
  
  public void setFeaturedImagePath(String featuredImagePath) {
      this.featuredImagePath = featuredImagePath;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><img src="https://i.imgur.com/4BYJIZx.png" alt="Debug image" title="Debug"></p>