title: Controller sends empty Object from Thymeleaf - Spring Boot
body: <p><strong>Hi Guys!</strong></p>
  <p>I have been implementing service in Spring Boot which
  allows users to send anonymouse questionaries to server.</p>
  <p>I have already implemented most of the backend like adding users etc. and right now I have been struggling with one action which take answers from user and sends into server (save in database).
  Object containing answers (filledSurvey) is being sent as empty. In this same logic in logging users fields from form are corectly send forward.</p>
  <p>This endpoint displays questionary:</p>
  <pre><code>@RequestMapping(path = {&quot;/try&quot;, &quot;/try/{id}&quot;})
      public String tryCompletingSurvey(Model model, @PathVariable(&quot;id&quot;) Long id) {
          Connection connection = connectionService.getConnection(id);
          FilledSurvey filledSurvey = connection.getSurvey().getTemplate();
  
          for (FilledQuestion filledQuestion : filledSurvey.getFilledQuestions()) {
              filledQuestion.getFilledAnswers().get(0).setCheck(true);
          }
  
          model.addAttribute(&quot;filledSurvey&quot;, filledSurvey);
  
          return &quot;completing/completing&quot;;
      }
  </code></pre>
  <p>This is thymeleaf html:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  
  &lt;head&gt;
      &lt;title&gt;Completing survey&lt;/title&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta http-equiv=&quot;x-ua-compatible&quot; content=&quot;ie=edge&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://use.fontawesome.com/releases/v5.4.1/css/all.css&quot;&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;center&gt;
      &lt;form action=&quot;#&quot; th:action=&quot;@{/user/surveys/finish}&quot; th:object=&quot;${filledSurvey}&quot; method=&quot;post&quot;&gt;
  
  &lt;!--        &lt;div th:each=&quot;question, questionStat : ${survey.getFilledQuestions()}&quot; &gt;--&gt;
  &lt;!--            &lt;p th:text=&quot;${question.getQuestion()}&quot;&gt;&lt;/p&gt;--&gt;
  &lt;!--            &lt;div th:each=&quot;answer, answerStat: ${question.getFilledAnswers()}&quot; &gt;--&gt;
  &lt;!--                &lt;input type=&quot;radio&quot;--&gt;
  &lt;!--                       th:name=&quot;question+${questionStat.index}&quot;--&gt;
  &lt;!--                       th:field=&quot;*{}&quot;--&gt;
  &lt;!--                       th:value=&quot;${true}&quot;&gt;--&gt;
  &lt;!--                &lt;label th:text=&quot;${answer.answer}&quot;&gt;--&gt;
  &lt;!--                &lt;/label&gt;--&gt;
  &lt;!--            &lt;/div&gt;--&gt;
  &lt;!--        &lt;/div&gt;--&gt;
  
          &lt;h2&gt;Survey name: &lt;/h2&gt;
          &lt;h3 th:text=&quot;${filledSurvey.getSurveyName()}&quot;&gt;&lt;/h3&gt;
  
          &lt;h2&gt;Number of questions: &lt;/h2&gt;
          &lt;h3 th:text=&quot;${filledSurvey.filledQuestions.size()}&quot;&gt;&lt;/h3&gt;
          &lt;div class=&quot;col-md-6&quot;&gt;
              &lt;input type=&quot;submit&quot; style=&quot;align-content: center&quot; class=&quot;btn btn-primary&quot; value=&quot;  Send  &quot;&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And this is endpoint which stores empty object from thymeleaf:</p>
  <pre><code>@RequestMapping(path = &quot;/finish&quot;, method = RequestMethod.POST)
      public String getHash(FilledSurvey filledSurvey) {
  
          StringBuilder sb = new StringBuilder();
          for (FilledQuestion question : filledSurvey.getFilledQuestions()) {
              for (FilledAnswer answer : question.getFilledAnswers()) {
                  if (answer.isCheck()) sb.append(answer.getAnswer());
              }
          }
          LocalDateTime date = LocalDateTime.now();
          sb.append(date);
  
          String hash = sb.toString();
          hash = Base64.getEncoder().encodeToString(sb.toString().getBytes());
          filledSurvey.setHash(hash);
  
          surveyMagazinService.addSurveyToMagazin(filledSurvey);
  
          return &quot;completing/finish&quot;;
      }
  </code></pre>
  <p>I changed code to automaticly mark answers for now.
  This the picture of the object in the next endpoint:
  <a href="https://i.stack.imgur.com/b42Rv.jpg" rel="nofollow noreferrer">filledSurvey object</a></p>
  <p>I am aware that this is common question but i have been looking for the answer for a while now and couldn't figure it out. I have no errors in the console as well. I would appreciate any help or feedback.</p>