title: Json request body to java object with spring-boot
body: <p>I have the following JSON Request</p>
  
  <pre><code>{
    "FreightCalculationRequest": {
      "Products": [
        {
          "sku": "123",
          "size": "S",
          "quantity": "1",
          "shipAlone": "True",
          "itemType": "Shoe"
        },
        {
          "sku": "123",
          "size": "S",
          "quantity": "1",
          "shipAlone": "True",
          "itemType": "Shoe"
        }
      ],
      "ShipToZip": "54452",
      "IsCommercial": "True"
    }
  }
  </code></pre>
  
  <p>I am trying to send this request to the API controller method as a custom java object, and then return that same object as a json formatted string. I am getting a response through postman however, for products, and shiptoZip i get a null, and for isCommercial I get false, but i don't even have false as a value for isCommercial in the request. What's going on? I don't know how to debug very well in Java as i basically am checking my app every time by typing mvn spring-boot:start</p>
  
  <p>here is my object that I am returning and using as a parameter into the controller method.</p>
  
  <pre><code>public class FreightCalculationRequest {
  
      private Product[] Products;
      private String ShipToZip;
      private boolean IsCommercial;
  
      public Product[] getProducts() { return this.Products; }
      public void setProducts(Product[] itemsRequest) { this.Products = itemsRequest; }
  
      public String getShipToZip() { return this.ShipToZip; }
      public void setShipToZip(String ShipToZip) { this.ShipToZip = ShipToZip; }
  
      public boolean getIsCommercial() { return this.IsCommercial; }
      public void setIsCommercial(boolean IsCommercial) { this.IsCommercial = IsCommercial; }
  
  }
  </code></pre>
  
  <p>and here is the controller method im calling</p>
  
  <pre><code>@RequestMapping(value = "/test", produces = MediaType.APPLICATION_JSON_VALUE,  method = RequestMethod.POST)
  FreightCalculationRequest TestCall(@RequestBody FreightCalculationRequest calculationRequest) {
      return calculationRequest;
  
  }
  </code></pre>
  
  <p>Why is my response not showing the same as the request coming in.</p>
  
  <p>update:
  I added @JsonProperty to my variables, and now the response looks like such</p>
  
  <pre><code>{
      "isCommercial": false,
      "shipToZip": null,
      "products": null,
      "Products": null,
      "ShipToZip": null,
      "IsCommercial": false
  }
  </code></pre>
  
  <p>Kind of lost a bit, also realized I can save my changes while mvn is running and it will auto compile the changes</p>
  
  <p>Update:
  So the itemType in my json was actually throwing an error when I initally remove the wrapping of "FreightCalculationRequest" in the json response, so i thought that was the issue, however itemType is actually an object in the code so it was due to me not putting in a valid property and reading the json parsing error thoroughly,  There were two solutions for me, wrapping the response in another class, or remove the FreightCalculationWrapping.</p>
  
  <p>I also learned that I need to add @JsonProperty to map the json</p>
  
  <p>Thanks SO</p>