I'm having a problem with trying to use WebClient ...
# spring
j
I'm having a problem with trying to use WebClient with Kotlin. I'm just trying to make a GET request, but I keep getting
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/html;charset=utf-8' not supported for bodyType
. Here's the service:
Copy code
val client = WebClient.builder()
                .baseUrl(apiUrl)
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.ALL_VALUE)
                .defaultHeader("X-API-TOKEN", apiToken)
                .build()

        return client.get()
                .uri("/$directoryId/mailinglists/$mailingListId")
                .accept(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML)
                .acceptCharset(Charset.forName("UTF-8"))
                .retrieve()
                .bodyToMono(GetMailingListResponse::class.java)
Here's the controller:
Copy code
@GetMapping("/directories/{directoryId}/mailinglists/{mailingListId}")
    fun handle(@PathVariable directoryId: String, @PathVariable mailingListId: String): Mono<ResponseEntity<GetMailingListResponse>> {
        val resp = service.createMailingList(directoryId, mailingListId)
        return resp.map {
            body -> ResponseEntity.ok(body)
        }
    }
Any help would be appreciated.
a
Seems the response is text/html, so webclient doesn't know how to convert that to a GetMailingListResponse
110 Views