简体   繁体   English

Spring webflux with webclient bodyToMono UnsupportedMediaTypeException 不支持内容类型“application/json”

[英]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.我有 spring 应用程序和 web 客户端调用其他 REST 端点。 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在测试期间,我在 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我使用的是不可变的,下面是 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.我已经被困在这里一段时间了。

Finally, I was able to solve the problem by setting the attribute最后,我能够通过设置属性来解决问题

@Value.Style(jdkOnly = true) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring WebClient put Mapping:不支持内容类型&#39;application / json&#39; - Spring WebClient put Mapping: Content type 'application/json' not supported RestTemplate内容类型“ application / json”不受支持 - RestTemplate Content type 'application/json' not supported Spring Rest 应用程序中的“不支持内容类型‘application/json;charset=UTF-8’” - "Content type 'application/json;charset=UTF-8' not supported" in Spring Rest application 当我尝试将 JSON 发送到 Spring 时,不支持内容类型“application/json;charset=UTF-8” - Content type 'application/json;charset=UTF-8' not supported, when i try send JSON to Spring 内容类型“application/json;charset=UTF-8”不支持 Spring Boot REST API - Content type 'application/json;charset=UTF-8' not supported Spring Boot REST API RestEasy - UnsupportedMediaTypeException:无法使用内容类型 - RestEasy - UnsupportedMediaTypeException: Cannot consume content type Spring 启动 controller 调用不支持内容类型 'application/json;charset=UTF-8' - Content type 'application/json;charset=UTF-8' not supported with Spring boot controller call 如何模拟 Spring WebFlux WebClient? - How to mock Spring WebFlux WebClient? 不支持 Spring/Postman 内容类型“application/octet-stream” - Spring/Postman Content type 'application/octet-stream' not supported Spring webflux:webClient put 调用 - Spring webflux : webClient put call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM