title: Spring boot set values in a list of model objects and return as JSON
body: <p>I am new to spring boot. I am trying to create a JSON list and return that as a response for a get request.</p>
  <p>This is what my controller has:</p>
  <pre><code>@GetMapping(&quot;/dataReport&quot;)
  public dataModel getDataReport(@RequestParam(value = &quot;Nbr&quot;, required = true)) {
              dataModel response = new dataModel();
              response = dataService.getDataItems();
              return response;
  }
  </code></pre>
  <p>dataService.java
  Service class</p>
  <pre><code>
  import java.math.BigDecimal;
  import java.time.ZonedDateTime;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.stereotype.Service;
  import model.dataModel;
  import model.CheckSpecs;
  
  import lombok.extern.slf4j.Slf4j;
  
  @Service
  @Slf4j
  public class dataService{
  
      public dataModel getDataItems() {
          dataModel response = new dataModel();
  
              response.setAcn(&quot;851&quot;);
  
              CheckSpecs c1 = new CheckSpecs();
              c1.setCheck(&quot;SVC -&quot;);
  
              CheckSpecs c2 = new CheckSpecs();
              c2.setCheck(&quot;B - 5&quot;);
  
              List&lt;CheckSpecs&gt; checkSpecsList = new ArrayList&lt;CheckSpecs&gt;();
              checkSpecsList.add(c1);
              checkSpecsList.add(c2);
              response.setCheckSpecs(checkSpecsList);
              
              return response;
  }
  
  </code></pre>
  <p>Main Model class
  dataModel.java</p>
  <pre><code>import lombok.Getter;
  import lombok.Setter;
  import lombok.ToString;
  
  @Getter
  @Setter
  @ToString
  public class dataModel {
  
      private String acn;
      private List&lt;CheckSpecs&gt; checkSpecs;
  }
  </code></pre>
  <p>Model class with object of main model class
  CheckSpecs.java</p>
  <pre><code>import java.math.BigDecimal;
  import java.time.ZonedDateTime;
  
  import lombok.Getter;
  import lombok.Setter;
  import lombok.ToString;
  
  @Getter
  @Setter
  @ToString
  public class CheckSpecs {
  
      private String check;
  }
  
  </code></pre>
  <p>Currently it's returning the value of string variable in the json response, but returning null for the list of model. Do i need to use string builder or JSONProperty?</p>
  <pre><code>{
    &quot;acn&quot;: &quot;851&quot;,
    &quot;checkSpecs&quot;: null,
  } 
  </code></pre>
  <p>Expected:</p>
  <pre><code>{
    &quot;acn&quot;: &quot;851&quot;,
    &quot;checkSpecs&quot;: [
      {
        &quot;check&quot;: &quot;xyz&quot;
      }
    ]
  }
  </code></pre>