如何使用Spring WebClient消耗Page <Entity>响应

时间:2019-07-24 07:41:28

标签: java spring rest spring-webflux

我有一个REST服务,该服务正在返回Page,同时从WebClient中使用它时会抛出以下异常。

我也尝试了CustomPageImpl,但是这个问题仍然存在。

Mono<CustomPageImpl<AssetDTO>> assetDTOMono = getWebClient()
.get()
.uri(getAeMaintenanceClientConfig().getAssetsByOrderNumberURI(), 
orderBuid, orderNumber)
.accept(MediaType.APPLICATION_JSON)
.headers(httpHeaders ->                 httpHeaders.set(SecurityTokenService.AUTHORIZATION_HEADER, securityTokenService.getTokenValue(badgeId)))
.retrieve()
.onStatus(HttpStatus.NOT_FOUND::equals, clientResponse -> Mono.error(new Exception(messageResolver.message(MessageKey.NOT_FOUND, orderBuid, orderNumber))))
.onStatus(HttpStatus.UNAUTHORIZED::equals, clientResponse -> Mono.error(new Exception(messageResolver.message(MessageKey.USER_UNAUTHORIZED))))
.bodyToMono(new ParameterizedTypeReference<CustomPageImpl<AssetDTO>>() {}).;

return assetDTOMono.block();

“ org.springframework.core.codec.CodecException:类型定义错误:[简单类型,类org.springframework.data.domain.Pageable];嵌套的异常是com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法org.springframework.data.domain.Pageable的构造实例(不存在像默认构造一样的创建者):抽象类型要么需要映射到具体类型,要么具有自定义反序列化器,要么包含其他类型信息”

这是我要呼叫的REST服务。

@ApiOperation(value = "Find Assets by OrderNumber and OrderBuid")
@GetMapping(value = "/assets", params = {"ordernumber", "orderbuid"})
public ResponseEntity<Page<AssetDTO>> findAssetsByOrderNumberAndBuidAndConditions(@RequestParam(value = "ordernumber") String orderNumber, @RequestParam(value = "orderbuid") Long orderBuid,
                                                                                  @RequestParam(value = "creationdate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime creationDate, @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @RequestParam(value = "shipdate", required = false) ZonedDateTime shipDate,
                                                                                  @RequestParam(value = "installdate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime installDate, @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @RequestParam(value = "deinstalldate", required = false) ZonedDateTime deInstallDate,
                                                                                  @ModelAttribute("bySOrder") AssetAdvancedSearchFilter bySOrder,
                                                                                  @SortDefault.SortDefaults(value = {
                                                                                          @SortDefault(value = "customerProductId", direction = Sort.Direction.DESC),
                                                                                          @SortDefault(value = "orderNum", direction = Sort.Direction.DESC),
                                                                                          @SortDefault(value = "orderTieNum", direction = Sort.Direction.ASC),
                                                                                          @SortDefault(value = "shippedDateTz", direction = Sort.Direction.DESC)}) Pageable pageable) {
    return ResponseEntity.ok().body(assetAdvancedService.findAssetsByAdvancedConditions(null, orderNumber, orderBuid, creationDate, shipDate, installDate, deInstallDate, bySOrder, pageable));
}

0 个答案:

没有答案