title: How to solve the error: Invalid JSON input: Cannot deserialize instance of Topic out of START_ARRAY token
body: <p>I am developing a survey application that uses a Springboot Rest API and a ReactJS front end and I a faced with a seemingly unsolvable problem. In my Springboot application, I have a bean called Topic which is written as follows:</p>
  
  <pre><code>@Entity
  public class Topic {
      @Id
      @GeneratedValue
      private Long id;
  
      private String question;
  
      @NotNull
      @Size(min=3, max=20)
      private String topic;
  
      @Column(precision=4, scale=1)
      private double npm = 0;
  
      @OneToMany(mappedBy = "topic")
      private Set&lt;Submission&gt; submissions;
  
      public Topic()
      {
          super();
      }
  
      public Topic(Long id, String topic, double npm)
      {
          super();
          this.id = id;
          this.setTopic(topic);
          this.setNpm(npm);
      }
  
      public Long getID()
      {
          return this.id;
      }
  
      public void setId(Long id)
      {
          this.id = id;
      }
  
      /**
       * @return the topic
       */
      public String getTopic() {
          return topic;
      }
  
      /**
       * @param topic the topic to set
       */
      public void setTopic(String topic) {
          this.topic = topic;
      }
  
      /**
       * @return the npm
       */
      public double getNpm() {
          return npm;
      }
  
      /**
       * @param npm the npm to set
       */
      public void setNpm(double npm) {
          this.npm = npm;
      }
  
      /**
       * @return the question
       */
      public String getQuestion() {
          return question;
      }
  
      /**
       * @param question the question to set
       */
      public void setQuestion(String question) {
          this.question = question;
      }
  
  }
  </code></pre>
  
  <p>and a Repository class:</p>
  
  <pre><code>@Repository
  public interface TopicRepository extends JpaRepository&lt;Topic, Long&gt;{
  
      @Transactional
      @Modifying
      @Query("UPDATE Topic SET npm = ?1 WHERE id = ?2")
      public void updateNpm(double newNpm, long id);
  
      @Query("SELECT topic FROM Topic")
      public List&lt;String&gt; getTopics();
  
  }
  </code></pre>
  
  <p>Finally, my Controller class is as follows (I have omitted methods that are not causing problems):</p>
  
  <pre><code>@RestController
  public class TopicResource {
  
      @Autowired
      private TopicRepository topicRepository;
  
      @CrossOrigin
      @PostMapping("/topics")
      public void createTopic(@RequestBody Topic topic)
      {
          Topic savedTopic = topicRepository.save(topic);
      }
  }
  </code></pre>
  
  <p>In my React application, I am making a POST request from the following component Class:</p>
  
  <pre><code>import React, { Component } from 'react';
  import './Styling/createsurvey.css'
  
  class CreateSurvey extends Component {
  
      constructor () {
          super();
          this.state = {
              topic: '',
              question: ''
          };
  
          this.handleTopicChange = this.handleTopicChange.bind(this);
          this.handleQuestionChange = this.handleQuestionChange.bind(this);
          //this.printState = this.printState.bind(this);
          this.handleSubmit = this.handleSubmit.bind(this);
      }
  
      handleTopicChange(e) {
          this.setState({
              topic: e.target.value
          });
      }
  
      handleQuestionChange(e) {
          this.setState({
              question: e.target.value
          });
      }
  
      handleSubmit(event) {
          event.preventDefault();
  
          console.log(this.state.topic);
          console.log(this.state.question);
  
          fetch('http://localhost:8080/topics', {
              method: 'post',
              headers: {'Content-Type':'application/json'},
              body: {
                  "npm": "0",
                  "topic": "Turkey",
                  "question": "How is life here",
                  "submissions": {}
              }
             });
  
  
      }
  
      render() {
          return(
             &lt;div&gt;
                 &lt;form onSubmit={this.handleSubmit}&gt;
                     &lt;h2&gt;Create a new Survey&lt;/h2&gt;
                     &lt;br&gt;&lt;/br&gt;
                     &lt;div className="form-group"&gt;
                          &lt;label&gt;&lt;strong&gt;Enter the survery topic: &lt;/strong&gt;&lt;/label&gt;
                          &lt;br&gt;&lt;/br&gt;
                          &lt;input 
                          className="form-control" 
                          placeholder="Enter a cool topic to ask a question about"
                          align="left"
                          onChange={this.handleTopicChange}&gt;        
                          &lt;/input&gt;
                     &lt;/div&gt;
                     &lt;div className="form-group"&gt;
                          &lt;label&gt;&lt;strong&gt;Enter a survey question: &lt;/strong&gt;&lt;/label&gt;
                          &lt;br&gt;&lt;/br&gt;
                          &lt;textarea
                          className="form-control" 
                          placeholder="Ask your question here. The customer will give an answer on a scale from 1 to 10."
                          align="left"
                          rows="3"
                          onChange={this.handleQuestionChange}&gt;        
                          &lt;/textarea&gt;
                     &lt;/div&gt;
                     &lt;div className="form-group"&gt;
                      &lt;button type="submit" className="btn btn-primary"&gt;Submit Your Question&lt;/button&gt;
                     &lt;/div&gt;   
              &lt;/form&gt;
             &lt;/div&gt;
          );
      }
  
  }
  
  export default CreateSurvey;
  </code></pre>
  
  <p>I am faced with the following error:</p>
  
  <pre><code>2020-03-03 01:15:17.862 DEBUG 17816 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : POST "/topics", parameters={}
  2020-03-03 01:15:17.862 DEBUG 17816 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.recommend.me.springboot.rest.recommendme.topic.TopicResource#createTopic(Topic)
  2020-03-03 01:15:17.867 DEBUG 17816 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Could not resolve parameter [0] in public void com.recommend.me.springboot.rest.recommendme.topic.TopicResource.createTopic(com.recommend.me.springboot.rest.recommendme.topic.Topic): Invalid JSON input: Cannot deserialize instance of `com.recommend.me.springboot.rest.recommendme.topic.Topic` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.recommend.me.springboot.rest.recommendme.topic.Topic` out of START_ARRAY token
   at [Source: (PushbackInputStream); line: 1, column: 1]
  
  </code></pre>
  
  <p>Can someone point out what I am doing wrong with my request? I have tried all forms of JSON request formats yet nothing seems to work.</p>