Last active
December 31, 2018 11:09
-
-
Save hoangong/23cfcc1a63aed2e361b8428e86bcfe14 to your computer and use it in GitHub Desktop.
Generic pojo marshaller for akka http 2.4 #pojo #marsheller #akka-http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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