Code review comment: Added support for serializer config.

Code before review:
public Mono<U> getResult(PollingContext<T> pollingContext, TypeReference<U> resultType) {
if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.FAILED) {
return Mono.error(new RuntimeException("Long running operation failed."));
} else if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.USER_CANCELLED) {
return Mono.error(new RuntimeException("Long running operation canceled."));
}
String finalGetUrl;
String httpMethod = pollingContext.getData(HTTP_METHOD);
if ("PUT".equalsIgnoreCase(httpMethod) || "PATCH".equalsIgnoreCase(httpMethod)) {
finalGetUrl = pollingContext.getData(REQUEST_URL);
} else if ("POST".equalsIgnoreCase(httpMethod) && pollingContext.getData(LOCATION) != null) {
finalGetUrl = pollingContext.getData(LOCATION);
} else {
throw logger.logExceptionAsError(new RuntimeException("Cannot get final result"));
}
if (finalGetUrl == null) {
String latestResponseBody = pollingContext.getData(POLL_RESPONSE_BODY);
if (TypeUtil.isTypeOrSubTypeOf(BinaryData.class, resultType.getJavaType())) {
return (Mono<U>) Mono.just(BinaryData.fromString(latestResponseBody));
} else {
return Mono.fromCallable(() -> serializer.deserialize(latestResponseBody, resultType.getJavaType(),
SerializerEncoding.JSON));
}
} else {
HttpRequest request = new HttpRequest(HttpMethod.GET, finalGetUrl);
Mono<HttpResponse> responseMono;
if (context == null) {
responseMono = httpPipeline.send(request);
} else {
responseMono = httpPipeline.send(request, context);
}
return responseMono.flatMap(res -> {
if (TypeUtil.isTypeOrSubTypeOf(BinaryData.class, resultType.getJavaType())) {
return (Mono<U>) BinaryData.fromFlux(res.getBody());
} else {
return res.getBodyAsString().flatMap(body -> Mono.fromCallable(() ->
serializer.deserialize(body, resultType.getJavaType(), SerializerEncoding.JSON)));
}
});
}
}

Line under review: SerializerEncoding.JSON));

Code after addressing the review:
public Mono<U> getResult(PollingContext<T> pollingContext, TypeReference<U> resultType) {
if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.FAILED) {
return Mono.error(new AzureException("Long running operation failed."));
} else if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.USER_CANCELLED) {
return Mono.error(new AzureException("Long running operation cancelled."));
}
String finalGetUrl;
String httpMethod = pollingContext.getData(PollingConstants.HTTP_METHOD);
if (HttpMethod.PUT.name().equalsIgnoreCase(httpMethod)
|| HttpMethod.PATCH.name().equalsIgnoreCase(httpMethod)) {
finalGetUrl = pollingContext.getData(PollingConstants.REQUEST_URL);
} else if (HttpMethod.POST.name().equalsIgnoreCase(httpMethod)
&& pollingContext.getData(PollingConstants.LOCATION) != null) {
finalGetUrl = pollingContext.getData(PollingConstants.LOCATION);
} else {
return Mono.error(new AzureException("Cannot get final result"));
}
if (finalGetUrl == null) {
String latestResponseBody = pollingContext.getData(PollingConstants.POLL_RESPONSE_BODY);
return PollingUtils.deserializeResponse(BinaryData.fromString(latestResponseBody), serializer, resultType);
} else {
HttpRequest request = new HttpRequest(HttpMethod.GET, finalGetUrl);
return httpPipeline.send(request)
.flatMap(HttpResponse::getBodyAsByteArray)
.map(BinaryData::fromBytes)
.flatMap(binaryData -> PollingUtils.deserializeResponse(binaryData, serializer, resultType));
}
}