Document how to integrate other JSON libs via Support traits explicitly
- Dominant language
- Scala
- Stars
- 1.4k
- Forks
- 584
- Avg merge
- 14h 33m
- Merged PRs (30d)
- 24
Description
**Issue by [acjay](https://github.com/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](https://github.com/travisbrown/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`](http://doc.akka.io/docs/akka-stream-and-http-experimental/current/scala/http/routing-dsl/directives/marshalling-directives/entity.html#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?
Contributor guide
Research direction
Start with the entity directive documentation linked in the issue and inspect the Support traits involved in custom JSON unmarshalling. Document how another JSON library can integrate explicitly, including the application/json content type behavior and the relevant unmarshaller setup. Done means a newcomer can follow the documented integration without relying on implicit inference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100