title: POST array in RequestBody to Spring Controller as List of Objects
body: <p>I'm fairly new to Spring, and I've looked at many posts about similar scenarios, but I have yet to figure this out. </p>
  
  <p>I'm trying to alter an existing (working) endpoint in my project to pass an array of <code>Region</code> objects from Angular frontend to a list or other collection in Spring backend. Most of my attempts have resulted in the error: <code>Bad argument(s) for enum JSON parse error: Cannot deserialize instance of java.util.ArrayList&lt;com.cigna.apps.shapeup.domain.Region&gt; out of START_OBJECT token</code>.</p>
  
  <p>Here is my frontend API call:</p>
  
  <pre><code>createCampaignReports(apiRoot: HateoasResponse, campaignId: number, regionList: Region[]): Observable&lt;Action&gt; {
      if (hasHref(apiRoot, this.links.reports)) {
        let params: HttpParams = new HttpParams();
        params = params.set('campaignId', campaignId.toString());
        return this.httpClient.post(getHref(apiRoot, this.links.reports), {regionList}, {params: params})
  
      ...other code...
  
      }
    }
  </code></pre>
  
  <p>And here is a stringified sample array from my frontend:</p>
  
  <pre><code>[
    {
      "sid": 2,
      "region": "New Zealand"
    },
    {
      "sid": 18,
      "region": "Middle East"
    },
    {
      "sid": 19,
      "region": "Kenya"
    }
  ]
  </code></pre>
  
  <p>My Spring Controller:</p>
  
  <pre><code>@PostMapping("/reports")
      ResponseEntity&lt;ApiResponse&gt; generateReports(@RequestParam(value = 'campaignId', required = true) Integer campaignId,
                                                  @RequestBody (required = false) List&lt;Region&gt; regionList,
                                                  HttpServletRequest request,
                                                  HttpServletResponse response) {
  ...other code...
  
  def user = userService.getUser(userId)
  def report = portalService.generateReport(user, campaignId, regionList)
  
  ...
  </code></pre>
  
  <p>And finally, my Region class in the backend:</p>
  
  <pre><code>class Region extends BaseEntity {
  
      String region
  
      int age
  }
  </code></pre>