title: Spring boot MongoRepository - Store JSON in Mongodb
body: <p>I am learning spring boot and am able to create a simple API that takes the array of products (in json ) as input and stores them in MongoDB.</p>
  <p>Here is how the POST input looks like</p>
  <p><strong>NOTE:</strong> Number of fields and their name could vary, in some products, it could be 10 and in others it could be 20.</p>
  <pre><code>{&quot;product&quot;:{
      &quot;uniqueId&quot;: &quot;6374848&quot;,
      &quot;handle&quot;: &quot;polka blanket vanilla&quot;,
      &quot;title&quot;: &quot;Polka Dot Blanket&quot;,
      &quot;vendor&quot;: &quot;Johnson&quot;,
      &quot;type&quot;: &quot;Home&quot;
  }}
  </code></pre>
  <p>I have created <code>Product.java</code> model like this</p>
  <pre><code>@Document
  public class Product {
  
      @Id
      private String id;
      private Map&lt;String,Object&gt; product;
  
      public Product(){
          this.product = new HashMap&lt;String,Object&gt;();
      }
      
      public void setProduct(Map&lt;String,Object&gt; product){
          // System.out.println(&quot;setting Product attributes&quot;);
          // System.out.println(product.toString());
          this.product = product;
  
      }
      
      public Map&lt;String, Object&gt; getProduct(){
          return this.product;
      }
  }
  </code></pre>
  <p>Controller Code</p>
  <pre><code>    @PostMapping(&quot;/product&quot;)
      public void FeedConsume(@RequestBody Product product, @RequestParam(value = &quot;site_name&quot;) String siteName, @RequestParam(value = &quot;site_key&quot;) String siteKey){
          
          productRepo.save(product);
      
      }
  </code></pre>
  <p>Problem is: I am able to store the JSON object in MongoDb like this</p>
  <pre><code>{id:OjectId(&quot;asdfs&quot;),
  &quot;product&quot;:{
      &quot;uniqueId&quot;: &quot;6374848&quot;,
      &quot;handle&quot;: &quot;polka blanket vanilla&quot;,
      &quot;title&quot;: &quot;Polka Dot Blanket&quot;,
      &quot;vendor&quot;: &quot;Johnson&quot;,
      &quot;type&quot;: &quot;Home&quot;
  }}
  
  </code></pre>
  <p>However, what I want is to store it in Mongo Like this</p>
  <pre><code>{id:ObjectId(&quot;asdfsd&quot;),
   &quot;uniqueId&quot;: &quot;6374848&quot;,
   &quot;handle&quot;: &quot;polka blanket vanilla&quot;,
   &quot;title&quot;: &quot;Polka Dot Blanket&quot;,
   &quot;vendor&quot;: &quot;Johnson&quot;,
  &quot;type&quot;: &quot;Home&quot;
  }
  
  </code></pre>
  <p>As I am new to Jackson and spring boot, I tried a few <code>Jackson</code> annotations didn't work. Any help how can I achieve the solution.</p>