title: How would you handle a REST API with only optional query params with Spring Boot?
body: <p>I want to build a simple endpoint that returns an <code>Order</code> object where I can search for this order by a single query parameter or a combination of several query parameters altogether. All of these query parameters are optional and the reason is that different people will access these orders based on the different Ids. </p>
  
  <p>So for example:
  <code>/order/items?itemId={itemId}&amp;orderId={orderId}&amp;deliveryId={deliveryId}&amp;packetId={packetId}</code></p>
  
  <pre><code>@GetMapping(path = "/order/items", produces = "application/json")
  public Order getOrders(@RequestParam Optional&lt;String&gt; itemId,
                                @RequestParam Optional&lt;String&gt; orderId,
                                @RequestParam Optional&lt;String&gt; deliveryId,
                                @RequestParam Optional&lt;String&gt; packetId) { }
  </code></pre>
  
  <p>I could of course also skip the Java Optional and use <code>@RequestParam(required = false)</code>, but the question here is rather how do I escape the <code>if-else</code> or <code>.isPresent()</code> nightmare of checking whether the query params are null? Or is there an elegant way, depending on the constellation of params, to pass further to my service and Spring Data JPA repository. </p>