title: Spring Boot Controller does not recognize Path Variable as optional
body: <p>Using Spring Boot, I have implemented a RestController like so:</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/api/v1/student/img&quot;)
  @CrossOrigin(&quot;*&quot;)
  public class ProfilePictureController {
  
      @GetMapping( &quot;/{studentId}&quot;)
      public void getProfilePicture(@PathVariable(required = false) Long studentId, HttpServletResponse response) throws IOException {
          Optional&lt;ProfilePicture&gt; profilePicture;
          if (studentId != null) {
              profilePicture= studentService.getProfilePictureByStudentId(studentId);
          } else {
              profilePicture= studentService.getProfilePicture(1L);
          }
          if (profilePicture.isPresent()) {
              ServletOutputStream outputStream = response.getOutputStream();
              outputStream.write(profilePicture.get().getImage());
              outputStream.close();
          }
      }
  </code></pre>
  <p>My ProfilePicture-class contains a variable &quot;image&quot;, which is of type byte[]. I am trying to retrieve this variable.</p>
  <p>Anyways, the issue is that my controller does not seem to treat my PathVariable as optional. If I use the fetch-API to send a GET request with the following URL:</p>
  <p><code>const url = &quot;http://localhost:8080/api/v1/student/img/&quot;</code>,</p>
  <p>I am getting an error:</p>
  <p><code>'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: &quot;img&quot;</code>.</p>
  <p>Does anyone know what might be the issue?</p>