Search code examples
javafirebasegoogle-cloud-firestorehashmappojo

How would I create a POJO class for such a data structure?


My data structure in firestore database is supposed to look like this

enter image description here

As from the image, the our_array field, is an array that contains fields of data type - Map inside it.

I need to create a simple POJO in order to insert the data as designed.

My current POJO class:

class ProductList{
  private boolean availability;
  private Object[] our_array; //I have doubts about this one
  private String product_title;

  … //Getters & setters
}

How can I structure the above data set, spefically the our_maps array that contains Map(s) inside it?


Solution

  • First create a Product pojo :

    class Product {
      private String productName;
      … 
      …
      // getters / setters
    }
    

    then your ProductList class could have a list of Products instead :

    class ProductList {
      private boolean availability;
      private List<Product> our_productList; 
      ...
      //Getters & setters
    }