Skip to content

Instantly share code, notes, and snippets.

@hoangong
Last active December 31, 2018 11:09
Show Gist options
  • Save hoangong/23cfcc1a63aed2e361b8428e86bcfe14 to your computer and use it in GitHub Desktop.
Save hoangong/23cfcc1a63aed2e361b8428e86bcfe14 to your computer and use it in GitHub Desktop.
Generic pojo marshaller for akka http 2.4 #pojo #marsheller #akka-http
import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
import com.fasterxml.jackson.databind.ObjectMapper
import com.voi.dto.response.HealthCheck
trait HealthCheckEndpoint {
val mapper = new ObjectMapper()
implicit def genericPojoMarshaller[T]: ToEntityMarshaller[T] =
Marshaller.withFixedContentType(ContentTypes.`application/json`)(o => HttpEntity(ContentTypes.`application/json`, mapper.writeValueAsString(o)))
lazy val healthCheckApi = path("health-check") {
get {
complete {
new HealthCheck().withIsHealthy(true)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment