WebClient loses zone when fetching data from another service

57 Views Asked by At

I am trying to get data from another service. The database has fields like time stamp with zone.

creation_date TIMESTAMP WITH TIME ZONE NOT NULL

In model creationDate is ZonedDateTime.

I store dates in UTC+0 and want them to be up to date for any zone when requested. In the service, I solved this problem by adding a zone to the mapper.

.creationDate(notificationsHistory.getCreationDate().withZoneSameInstant(ZoneId.systemDefault()))

When I try to get data using the webClient from this service, I get the dates again in UTC+0, although I get UTC+3 (default time zone) directly from the service

In Service:

"creationDate": "2022-04-23T13:19:49.361144 +03:00"

(time in UTC+3)

In WebClient query:

"creationDate": "2022-04-23T10:19:49.361144Z"

(time in UTC+0)

Here is my request to service:

    webClient.get()
      .uri(uriBuilder -> uriBuilder
        .path("...")
        .build(...))
      .retrieve()
      .bodyToMono(Dto.class)
      .block();

Here is my WebClient configuration:

  @Bean
  public WebClient webClient() {
    return WebClient.builder()
      .baseUrl(URI)
      .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
      .build();
  }

creationDate in model:

 @Schema(
   description = "Date of creation"
 )
 private ZonedDateTime creationDate;

Apparently, I'm losing the zone already with bodyToMono(Dto.class);

Can I somehow configure the webClient to not lose the zone? It is very important that there is the right time from any zone.

0

There are 0 best solutions below