-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
akka-http integration #4
Labels
Comments
Hm... This code should be enough to implement Tethys support in akka-http I think: import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import akka.http.scaladsl.model.ContentTypeRange
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import akka.util.ByteString
import tethys._
import tethys.jackson._
import scala.reflect.ClassTag
trait TethysSupport {
lazy val unmarshallerContentTypes: Seq[ContentTypeRange] = List(`application/json`)
implicit def unmarshaller[A](implicit reader: JsonReader[A]): FromEntityUnmarshaller[A] = {
Unmarshaller.byteStringUnmarshaller
.forContentTypes(unmarshallerContentTypes: _*)
.mapWithCharset {
case (ByteString.empty, _) => throw Unmarshaller.NoContentException
case (data, charset) => data.decodeString(charset.nioCharset.name).jsonAs[A].fold(throw _, identity)
}
}
implicit def marshaller[A](implicit ct: ClassTag[A], writer: JsonWriter[A]): ToEntityMarshaller[A] = {
Marshaller.stringMarshaller(`application/json`).compose(_.asJson)
}
} Show we place it as separated module or just as an example? |
Is there some concern about suggesting PR to https://github.com/hseeberger/akka-http-json? |
dos65
added a commit
that referenced
this issue
Aug 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: