How to check Webclient reposebody?

61 views Asked by At

i developed external API by WebClient but i don't know how to check the response body..

public class Call {
  public Mono<Object> get() {
    Mono<Object> http = webClient.get()
        .uri(EXTERNAL_URL)
        .retrieve()
        .bodyToMono(Object.class);

    return http;
  }
}

and test code

public class Test {
 @Test
 void test() {
  Call call = new Call();
  Mono<Object> mono = call.get();

  mono.doOnSuccess(
        r -> log.info(">>> r = {}", r) // 
  ).subscribe() }

  
}

log content

>>> r = MonoMap

it just print "MonoMap".. how can i check response body??

1

There are 1 answers

0
namila007 On

Change your code as follows, it will deserialize the response to a string and return

public Mono<String> get() {
    Mono<Object> http = webClient.get()
        .uri(EXTERNAL_URL)
        .retrieve()
        .bodyToMono(String.class);

    return String;
  }