create a HttpRequest that POSTs this POJO as JSON to a url ( how to transform the POJO to the required RequestEntity )
send the request using Http.singleRequest(request) // this is clear
transform the response from a json string back to a POJO ..
currently, I managed (with a lot of trial and error to deserialize a json back to a POJO like this)
public CompletionStage<Authorization> retrieve() {
Unmarshaller<ByteString, AccessTokenDTO> unmarshaller = Jackson
.byteStringUnmarshaller(AccessTokenDTO.class);
return http
.singleRequest(createRequest()).thenCompose(resp ->
resp
.entity()
.getDataBytes()
.fold(ByteString.emptyByteString(), (bs1, bs2) -> bs1.concat(bs2))
.mapAsync(1, bs -> unmarshaller.unmarshal(bs, materializer)) // not very intuitive
.map(token -> Authorization.oauth2(token.getAccessToken()))
.runWith(Sink.head(), materializer)
);
}
but this is way way way way way harder than it has to be.
I'm still clueless on what is the proposed way on how to serialize+send a pojo as json to another server...
This is worse than what you describe for #3373 because here the javadsl API to invoke marshallers seems to be missing and converting from the Scala types is somewhat hard from Java. I'll try to cook up an example.
The documentation about marshalling / unmarshalling ( https://doc.akka.io/docs/akka-http/current/common/marshalling.html?language=java ) only looks at the server-api, leaving one clueless on how to handle simple tasks using the akka-http client, like
currently, I managed (with a lot of trial and error to deserialize a json back to a POJO like this)
but this is way way way way way harder than it has to be. I'm still clueless on what is the proposed way on how to serialize+send a pojo as json to another server...