1

I am using a Quarkus application which have a dependent client service which pass me the response as a Uni object type

Uni<Response> response = clinetService.someMethod(id);

Now I need to pass this response to a another client cache service as a String:

cacheService(id, mapObj, responseObjectAsAString);

So I need to pass this converted String value to the above method.

I tried multiple ways to serialize/convert it into a String using ObjectMapper writeValueAsString(obj) method or Gson class .toJson(obj), but nothing worked.

Any suggestion will be very helpful.

2
  • What is Response? And what is clinetService? Commented Aug 30, 2023 at 10:35
  • Response is a class of jakarta.ws.rs.core library. clientService is an object of a class provided by a client service, output of which is an object of type Uni<Response>. Commented Aug 30, 2023 at 10:39

1 Answer 1

0

You actually have to solve two tasks:

  1. Convert the Uni<Response> into a Uni<String>
  2. Convert the Uni<String> into a String

The first can probably be as easy as this:

Uni<String> body = response.map(r -> r.readEntity(String.class));

The second can be done using UniAwait. A full example:

String body = response.map(r -> r.readEntity(String.class))
        .await()
        .indefinitely();

You can also use atMost instead of indefinitely, and you can put asOptional() between await() and indefinitely() to return an Optional<String> instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.