title: Gson: java.util.Map convert all key-value pairs
body: <p>I have following code:</p>
  
  <pre><code>Collection&lt;Product&gt; products = productRepository.findProducts(from, pageSize);
  
      Map&lt;Product, BigDecimal&gt; map = new TreeMap&lt;&gt;(new ProductComparator());
      for (Product product : products) {
          BigDecimal buyPrice = warehouseView.find(product.getId()).getBuyPrice();
          map.put(product, buyPrice);
      }
  
      Gson gson = new Gson();
      String json = gson.toJson(map);
      TypeToken mapType = new TypeToken&lt;Map&lt;Product, BigDecimal&gt;&gt;(){}.getType();
      String json2 = gson.toJson(map, mapType);
      JsonElement json3 = gson.toJsonTree(map, mapType);
  </code></pre>
  
  <p><strong><em>EXPLANATION</em></strong>: I have 5 products returned from DB, then for each of this products I call DB to get buy price. DB may return 0 - which indicates that given product not present in the warehouse.</p>
  
  <p><strong><em>So what I want to achieve</em></strong>: get json object, which has all 5 Products.</p>
  
  <p><strong><em>What is now</em></strong>: if for example for 3 products DB return 0 - I will get only 2 of my Products converted to json.</p>
  
  <p>I've tried different versions of converting e.g. <code>json</code>, <code>json2</code>, <code>json3</code> - but none of those worked.</p>
  
  <p>So how to convert full Map object with <code>0</code> values ?</p>