Scala Akka HTTP casting parameter as java.time.ZonedDateTime

强颜欢笑 提交于 2019-12-01 12:38:59

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)
          }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!