Pramod Shashidhara
Pramod Shashidhara

Reputation: 959

Spring webflux with webclient bodyToMono UnsupportedMediaTypeException Content type 'application/json' not supported

I have spring application with web client making calls to other REST end-points. Below is the client -

@Override
public Mono<SearchPrincipalsByResourceResponse> searchPrincipalsByResource(SearchPrincipalsByResourceRequest searchPrincipalsByResourceRequest) {
    return webClient
            .post()
            .uri(uriBuilder -> uriBuilder.path(BASE_PATH + SEARCH_PRINCIPALS_BY_RESOURCE_PATH).build())
            .accept(APPLICATION_JSON)
            .body(Mono.just(searchPrincipalsByResourceRequest), SearchPrincipalsByResourceRequest.class)
            .retrieve()
            .bodyToMono(SearchPrincipalsByResourceResponse.class);
}

During testing, I get this error exactly at bodyToMono

Suppressed: org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json' not supported for bodyType=io.atlassian.identity.directorymerge.perms.model.SearchPrincipalsByResourceResponse

I'm using immutable and below is the SearchPrincipalsByResourceResponse class

@Value.Immutable
@JsonAutoDetect
@JsonSerialize(as = ImmutableSearchPrincipalsByResourceResponse.class)
@JsonDeserialize(as = ImmutableSearchPrincipalsByResourceResponse.class)
public abstract class SearchPrincipalsByResourceResponse {
    public abstract List<SearchResult> getResults();
}

Any help is much appreciated. I have been stuck here for a while now.

Upvotes: 3

Views: 1473

Answers (1)

Pramod Shashidhara
Pramod Shashidhara

Reputation: 959

Finally, I was able to solve the problem by setting the attribute

@Value.Style(jdkOnly = true) 

Upvotes: 1

Related Questions