title: Spring Boot - Unable to De-serialize JSON Object Sent by Fetch
body: <p>I'm trying to send a JSON object from the front-end js to Spring Boot.
  I keep getting the following error in Spring Boot</p>
  <blockquote>
  <p>Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type <code>com.c3.healthapp.model.HeartRateEntry</code> from Array value (token <code>JsonToken.START_ARRAY</code>); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type <code>com.c3.healthapp.model.HeartRateEntry</code> from Array value (token <code>JsonToken.START_ARRAY</code>)&lt;EOL&gt; at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]]</p>
  </blockquote>
  <p>and a status 400 on the client side.</p>
  <p>The Javascript function being used to send is</p>
  <pre><code>function saveEntryToDB(entry){
      fetch(&quot;/customer/heartrate/save&quot;, {
        method: &quot;POST&quot;,
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify(entry)
      }).then(res =&gt; {
        console.log(&quot;User saved. response:&quot;, res);
      });
  }
  </code></pre>
  <p>The object being sent</p>
  <pre><code>{
  entryHeartRate: 55, 
  dateOfEntry: Tue Mar 01 2022 00:00:00 GMT+0000 (Greenwich Mean Time)
  }
  </code></pre>
  <p>Spring boot controller method</p>
  <pre><code>    @PostMapping(&quot;/heartrate/save&quot;)
      public ResponseEntity&lt;String&gt; saveHeartRate(@RequestBody HeartRateEntry heartRateEntry) {
          String username = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
          Customer customer = customerService.getCustomer(username);
          customer.getHeartRateEntries().add(heartRateEntry);
          customerService.saveCustomer(customer);
          URI uri = URI.create(ServletUriComponentsBuilder.fromCurrentContextPath().path(&quot;/heartrate/save&quot;).toUriString());
          return ResponseEntity.created(uri).body(&quot;Saved!&quot;);
      }
  </code></pre>
  <p>and HeartRateEntry class</p>
  <pre><code>@Entity
  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class HeartRateEntry {
      @Id
      @GeneratedValue(strategy = IDENTITY)
      private Long entryId;
      private int entryHeartRate;
      private Date dateOfEntry;
  
      @Override
      public String toString() {
  
          return &quot;Entry Id: &quot; + entryId + &quot; Entry Heart Rate: &quot; + entryHeartRate + &quot; Date Of Entry : &quot; + dateOfEntry;
  
      }
  }
  </code></pre>
  <p>So far, I've been able to submit other entities from HTML forms and get values (including an array of heart rate entries) returned from Spring Boot with no issues.</p>
  <p>I have tried formatting the date as dd/mm/yy and adding the annotation '@JsonFormat(pattern=&quot;dd/mm/yyyy&quot;)' to the dateOfEntry attribute in the HeartRateEntry class, in case it was somehow an issue with date parsing, but this doesn't seem to make a difference.</p>
  <p>I have also tried adding an id attribute to the JSON object prior to sending.
  This doesn't seem to make a difference either.</p>