title: How to pass local date in path variable in Spring Boot?
body: <p>I'm writing  REST service.</p>
  
  <p>I want to get all records by date that I pass in @Path variable.</p>
  
  <p><strong>How Can I do that?</strong></p>
  
  <p>What I tried to do:</p>
  
  <p>Model Class:</p>
  
  <pre><code>@Entity
  @Table(name = "test")
  public class Test {
  @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
  
      private String name;
  
  
      @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
      private LocalDate beginDate;
  
  
      @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
      private LocalDate endDate;
  
  
      private String activity;
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>@Repository
  public interface TestRepository  extends JpaRepository&lt;Test, Integer&gt; {
  
      List&lt;Test&gt; findAllByName(String name);
  
      List&lt;Test&gt; findAllByBeginDate(LocalDate date);
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>@Service
  public class TestService {
  
  @Autowired
  private final TestRepository testRepository;
  
  public TestService(TestRepository testRepository) {
      this.testRepository = testRepository;
  }
  
  public List&lt;Test&gt; getAllTestsByBeginDate(LocalDate date) {
      return  testRepository.findAllByBeginDate(date);
     }
   }  
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@RestController
  @RequestMapping("/api/v1/")
  public class TestController {
  
      @GetMapping("test/all/{date}")
      public List&lt;Test&gt; getAllTestsByBeginDate(@PathVariable ("date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
  
  
      return testService.getAllTestsByBeginDate(date);
      }
    }
  </code></pre>
  
  <p>When I pass date like this, I get errors:</p>
  
  <p><a href="https://i.stack.imgur.com/wlxDK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wlxDK.jpg" alt="Postman Get Method"></a></p>