title: SpringBoot map an multivalue HTTP-header to a class
body: <p>By using <a href="https://www.rfc-editor.org/rfc/rfc7240" rel="nofollow noreferrer">RFC-7240</a>, we can define some preferences that we would like to be taken on the REST request that we made. For example, we can define whether an Update (PUT) request should return the resource or not. To me, this is a very good and kinda good approach to define what exactly we need.</p>
  <p>The preferences are defined using an HTTP-header called Prefer. Thanks to the @RequestHeader annotation we can easily get the request header in our controller, but then we need some boilerplate code to process the given header as the given value is a string, but it contains an array of key-values. Take the following request as an example:</p>
  <pre><code>POST /foo HTTP/1.1
  Host: example.org
  Prefer: handling=lenient, wait=100, respond-async
  Date: Tue, 20 Dec 2011 12:34:56 GMT
  </code></pre>
  <p>in the given request we have 3 parameters and we need to write a code to split the given string into tokens and then again into pairs of key-values, and no need to say that some params might have invalid values (like an integer might be a string) or some missing.</p>
  <p>But it would be awesome if we could map the header into a class. with default values and hard types(like integers and strings). Is there any mechanism in spring to that automatically? I mean could we define a class for A HEADER (not a set of them) and then spring maps the params in the header to specified class?</p>