Document how to integrate other JSON libs via Support traits explicitly
#93 opened on Sep 8, 2016
Repository metrics
- Stars
- (1,311 stars)
- PR merge metrics
- (Avg merge 1d 10h) (2 merged PRs in 30d)
Description
Issue by acjay Friday Jan 08, 2016 at 05:05 GMT Originally opened as https://github.com/akka/akka/issues/19378
(cross-posted here http://stackoverflow.com/questions/34669848/akka-http-accept-application-json-in-post-requests)
I'm trying to use circe to do my JSON (de)serialization in an Akka-Http app, rather than spray-json. For that reason, I want to use the entity directive with as[String] to get the string representation of the request body, and then do my own deserialization. But it seems that entity is too smart for its own good, and is rejecting anything that does not have the Content-Type text/plain.
My understanding from the docs is that implicit magic should let me be able to do something like:
import akka.http.scaladsl.model.ContentTypes
entity(as[String].forContentTypes(ContentTypes.`application/json`))
But the compiler is not doing the whole thing of inferring that I want as to resolve to a FromEntityUnmarshaller[String], which has that implicit method forContentTypes, whose result should be converted to a FromMessageUnmarshaller[String], which (due to contravariance) should satisfy the need for a FromRequestUnmarshaller[String].
However, even holding the compilers hand by doing:
val jsonRequestToStringUnmarshaller: FromRequestUnmarshaller[String] =
messageUnmarshallerFromEntityUnmarshaller(implicitly[FromEntityUnmarshaller[String]].forContentTypes(ContentTypes.`application/json`))
entity(jsonRequestToStringUnmarshaller)
my server is still rejecting application/json requests.
What gives?