I have the following Deserializer
from a Spray project that I'd like to port over to Akka-Http. I'm just starting out with Akka-Http so I'm not to sure how I can port this code:
class urlParameterEnumDeserializer[T](enum: AppEnum[T]) extends Deserializer[String, T] {
def apply(s: String) = {
enum.valueOf(s).toRight(MalformedContent(s"Expected a valid string for ${enum} conversion. Found: ${s}"))
}
}
It used to allow me to convert incoming url parameters to my application's Enum types, for instance here's an implicit function that utilizes the Deserializer:
implicit val contentSourceDeserializer = new urlParameterEnumDeserializer[ContentSource](ContentSource)
How would I accomplish the same thing in Akka-Http?
Figured this out. Akka has some pre-canned marrshallers like
FromStringUnmarshaller
that help out. Here's how I converted my enum Deserializer to an Akka-Http UnMarshaller: