I\'m working on a REST service using Akka HTTP (in Scala). I would like a parameter that is passed in to a http get request to be converted to the ZonedDateTime type. The co
As ZonedDateTime
is not natively unmarshalled by Akka-HTTP, you will need to provide a custom unmarshaller to the parameters
directive.
This functionality is briefly described in the docs here.
Your unmarshaller can be created from a function by using Unmarshaller.strict
, e.g.
val stringToZonedDateTime = Unmarshaller.strict[String, ZonedDateTime](ZonedDateTime.parse)
This example assumes your param is provided in an ISO format. If it's not, you'll need to amend the unmarshalling function.
You can then use the unmarshaller passing it to the parameters directive:
parameters("testparam".as(stringToZonedDateTime)){
(testparam) =>
complete(testparam.toString)
}