static Mono < Object > decode ( HttpResponse httpResponse , SerializerAdapter serializer , HttpResponseDecodeData decodeData ) { ensureRequestSet ( httpResponse ) ; // return Mono . defer ( ( ) -> { if ( isErrorStatus ( httpResponse , decodeData ) ) { return httpResponse . bodyAsString ( ) . flatMap ( bodyString -> { try { final Object decodedErrorEntity = deserializeBody ( bodyString , decodeData . getUnexpectedException ( httpResponse . statusCode ( ) ) . exceptionBodyType ( ) , null , serializer , SerializerEncoding . fromHeaders ( httpResponse . headers ( ) ) ) ; return decodedErrorEntity == null ? Mono . empty ( ) : Mono . just ( decodedErrorEntity ) ; } catch ( IOException | MalformedValueException ignored ) { // This translates in RestProxy as a RestException with no deserialized body. // The response content will still be accessible via the .response() member. } return Mono . empty ( ) ; } ) ; } else if ( httpResponse . request ( ) . httpMethod ( ) == HttpMethod . HEAD ) { // RFC: A response to a HEAD method should not have a body. If so, it must be ignored return Mono . empty ( ) ; } else if ( ! isReturnTypeDecodable ( decodeData ) ) { return Mono . empty ( ) ; } else { return httpResponse . bodyAsString ( ) . flatMap ( bodyString -> { try { final Object decodedSuccessEntity = deserializeBody ( bodyString , extractEntityTypeFromReturnType ( decodeData ) , decodeData . returnValueWireType ( ) , serializer , SerializerEncoding . fromHeaders ( httpResponse . headers ( ) ) ) ; return decodedSuccessEntity == null ? Mono . empty ( ) : Mono . just ( decodedSuccessEntity ) ; } catch ( MalformedValueException e ) { return Mono . error ( new HttpRequestException ( "HTTP response has a malformed body." , httpResponse , e ) ) ; } catch ( IOException e ) { return Mono . error ( new HttpRequestException ( "Deserialization Failed." , httpResponse , e ) ) ; } } ) ; } } ) ; }
Decodes body of a http response .