How can I use http request headers for content negotiation in a Mashaller? How can I use http request headers for content negotiation in a Mashaller? json json

How can I use http request headers for content negotiation in a Mashaller?


Custom Marshallers section mentions Marshaller.oneOf overloaded methods, that seems to be what you want:

Helper for creating a "super-marshaller" from a number of "sub-marshallers". Content-negotiation determines, which "sub-marshaller" eventually gets to do the job.

The Marshaller companion object has many methods that receive a Seq[HttpHeader]. You can look into their implementations as well.

I don't have the time to look into the source code myself, but if this is not enough to put you on the right path, let me know.

Edit:

How about?

get {  optionalHeaderValueByName("JFORMAT") { format =>    complete {      format match {        case Some(f) => "Complete with json4s"        case _ => "Complete with trueaccord"      }    }  }}