How can I force the headers response?

My service response a String, my string is a json from another service, this response is a json, but my service responce with Content-Type: text/plain; charset=UTF-8.

Implementation of my service:

              String response = ((ResponseBody) confirmation).responseBody;
              response = "Miuler x";
              ResponseHeader responseHeader = ResponseHeader.OK
                .withHeader("Empresa", "Miuler")
                .withHeader("Content-Type", "application/json; charset=utf-8");
              return Pair.create(responseHeader, response);

response:

HTTP/1.1 200 OK
Empresa: Miuler
Date: Mon, 02 Dec 2019 17:33:04 GMT
Server: akka-http/10.1.10
Content-Type: text/plain; charset=UTF-8
Content-Length: 8

Miuler x

The header Empresa: Miuler is ok, but the header Content-Type: application/json; charset=utf-8"
is not set.

I already tried to add the header, but it doesn’t work, it always returns text/plain

  @Override
  public HeaderServiceCall<NotUsed, String> paymentCreditCard(String userName, String registerId) {
    return (requestHeader, notUsed) -> {
      CompletionStage<Pair<ResponseHeader, String>> pairCompletionStage;

      final EntityRef<RfCommand> ref = clusterSharding.entityRefFor(RfAggregate.ENTITY_TYPE_KEY, userName);

      pairCompletionStage = ref.
        <Confirmation>ask(replyTo -> new GetPaymentCreditCardCommand(UUID.fromString(registerId), replyTo), askTimeout)
        .thenApply(confirmation -> {
          if (confirmation instanceof ResponseBody) {
            String response = ((ResponseBody) confirmation).responseBody;

            response = "Miuler x";
            ResponseHeader responseHeader = ResponseHeader.OK
              .withHeader("Empresa", "Miuler")
              .withHeader("Content-Type", "application/json; charset=utf-8");
            return Pair.create(responseHeader, response);
          } else {
            throw new NotFound(((Rejected) confirmation).reason);
          }
          }
        );

      return pairCompletionStage;
    };
  }

and it does not work.

La forma correcta es pasar de String a akka.util.ByteString.

Hi @Miuler,

Lagom “enforces” StringMessageSerializer for String response type and by that Content-Type text/plain (this will override Content-Type set in service call implementation).
When you switched to ByteString response “enforcement” was skipped and your header override, in service call implementation, worked.
So if you want to use a String response type you can do a response Content-Type override by implementing Custom-serializer.

Br,
Alan