Again, not necessarily the best solution but ..
Note: Some of the code here is in Java, so you will need to do some digging/translation
Modifying the akka.http.marshallers.jackson.Jackson (Scala)
(possibly creating your own copy with the modifications)
Adding the following
def jsonAsString(): Unmarshaller[String] =
UnmarshallerImpl[String] { (_ec, _flowMaterializer) ⇒
implicit val ec = _ec
implicit val mat = _flowMaterializer
unmarshalling.Unmarshaller.messageUnmarshallerFromEntityUnmarshaller { // isn't implicitly inferred for unknown reasons
unmarshalling.Unmarshaller.stringUnmarshaller
.forContentTypes(`application/json`)
}
}(ClassTag(classOf[String]))
You can then use the RequestVal (java)
RequestVal<String> jsonStringExtractor = RequestVals.entityAs(MyJackson.jsonAsString());
To extract the JSON String
@Override
public Route createRoute() {
return route(
pathPrefix("jsontest").route(
post(handleWith(stringParser, (ctx, theRequest) -> {
System.out.println("JSON String :: "+theRequest);
return ctx.complete(createHttpResponse("OK"));
})))
);
Hope this helps, feedback is more than welcome
--
Mohamed