title: How can I parse nested JSON with multiple wrapper classes? (spring boot project)
body: <p>Make a sample Java service which takes the following json from an endpoint as input, parses it
  and puts it into the database.</p>
  
  <ol>
  <li><p>Input: ​ The input will have a fixed format which will be posted as a content body to the endpoint.</p></li>
  <li><p>Output: ​ The output should be a number of rows that are filled in the database or error in case of failures.</p></li>
  </ol>
  
  <p>Sample input : </p>
  
  <pre><code>   {
      "quiz": {
          "sport": {
                "q1": {
                    "question": "Which one is correct team name in NBA?",
                    "options": [
                          "New York Bulls",
                          "Los Angeles Kings",
                          "Golden State Warriros",
                          "Huston Rocket"
                          ],
                   "answer": "Huston Rocket"
                      }
                    },
           "maths": {
                 "q1": {
                     "question": "5 + 7 = ?",
                     "options": [
                              "10",
                              "11",
                              "12",
                              "13"
                             ],
                      "answer": "12"
                       },
                  "q2": {
                      "question": "12 - 8 = ?",
                      "options": [
                                "1",
                                "2",
                                "3",
                                "4"
                               ],
                       "answer": "4"
                        }
                     }
                 }
            }
  </code></pre>
  
  <p>I've created a basic Rest service with springboot that takes in question, options and answer as input, and also displays it in the same way.</p>
  
  <p>Ex. input : </p>
  
  <pre><code>   { 
       "question": "khis is the question part",
          "options": [
              "option 1",
              "option 2",
              "option 3",
              "option 4"
              ],
          "answer": "option 1"
         }
  </code></pre>
  
  <p>I have created a springboot project and created the following java classes:
  1. QuestionSet.java</p>
  
  <pre><code>package com.example.demo.questionset;
  
  import java.io.Serializable;
  
  import com.fasterxml.jackson.annotation.JsonRootName;
  
  
  
  public class QuestionSet {
  
      private String question;
      private String options[];
      private String answer;
  
  
      public QuestionSet() {
  
      }
  
  
  
  
  public QuestionSet(String question, String[] options, String answer) {
          super();
          this.question = question;
          this.options = options;
          this.answer = answer;
      }
  
  
      public String getQuestion() {
          return question;
      }
      public String[] getOptions() {
          return options;
      }
      public String getAnswer() {
          return answer;
      }
      public void setQuestion(String question) {
          this.question = question;
      }
      public void setOptions(String[] options) {
          this.options = options;
      }
      public void setAnswer(String answer) {
          this.answer = answer;
      }
      }
  </code></pre>
  
  <p>`</p>
  
  <ol start="2">
  <li><p>QuestionSetService.java</p>
  
  <pre><code>package com.example.demo.questionset;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.stereotype.Service;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.databind.ObjectWriter;
  
  
  @Service
  public class QuestionSetService {
  
  
  
  
  String nameString[] = {"kabir", "ram", "shyam", "varun"};
  </code></pre></li>
  <li><p>QuestionSetController.java</p></li>
  </ol>
  
  <p>package com.example.demo.questionset;</p>
  
  <pre><code> import java.util.List;
  
  
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  import com.fasterxml.jackson.annotation.JsonGetter;
  
     @RestController
     public class QuestionSetController {
  
  @Autowired
  QuestionSetService questionSetService;
  
  
  @RequestMapping("/questionsets")
  public List&lt;QuestionSet&gt; getAllQuestionSets(){
      return questionSetService.getAllQuestionSets();
  }
  
  @RequestMapping("/questionsets/{question}")
  public QuestionSet getQuestionSetByQuestion(@PathVariable String question)
   {
      return questionSetService.getQuestionSetByQuestion(question);
  }
  
  @PostMapping("/questionsets")
  public void postController(
    @RequestBody QuestionSet questionSet) {
  
      questionSetService.addQuestionSet(questionSet);
  }
  
    }
  
  
  
  
  
      private List&lt;QuestionSet&gt; questionSets = null;
  
  
      public List&lt;QuestionSet&gt; getAllQuestionSets() {
          return questionSets;
      }
  
      public QuestionSet getQuestionSetByQuestion(String question) {
          return questionSets.stream().filter(t -&gt;             
      t.getQuestion().equals(question)).findFirst().get();
      }
  
  
      public ResponseEntity addQuestionSet( QuestionSet questionSet) {
          questionSets.add(questionSet);
          return ResponseEntity.ok(HttpStatus.OK);
      }
  
       }
  </code></pre>
  
  <p>I can take in simple json input in the form of questionset but the required json input is much more complex. I understand that I need to make wrapper classes and use objectmapper, but I don't know how. </p>