Module methanol

Interface BodyAdapter.Decoder

All Superinterfaces:
BodyAdapter
All Known Implementing Classes:
ForwardingDecoder, StringDecoder
Enclosing interface:
BodyAdapter

public static interface BodyAdapter.Decoder extends BodyAdapter
A BodyAdapter that decodes response bodies into objects.
  • Method Details

    • toObject

      <T> HttpResponse.BodySubscriber<T> toObject(TypeRef<T> objectType, @Nullable MediaType mediaType)
      Returns a BodySubscriber that decodes the response body into an object of the given type using the format specified by the given media type. If mediaType is null, the decoder's default format parameters (e.g. charset) are used.
    • toDeferredObject

      default <T> HttpResponse.BodySubscriber<Supplier<T>> toDeferredObject(TypeRef<T> objectType, @Nullable MediaType mediaType)
      Returns a completed BodySubscriber that lazily decodes the response body into an object of the given type using the format specified by the given media type. If mediaType is null, the decoder's default format parameters (e.g. charset) are used.

      The default implementation returns a subscriber completed with a supplier that blocks ,uninterruptedly, on the subscriber returned by toObject(TypeRef, MediaType). Any completion exception raised while blocking is rethrown from the supplier as a CompletionException. Encoders that support reading from a blocking source should override this method to defer reading from such a source until the supplier is called.

    • installed

      static List<BodyAdapter.Decoder> installed()
      Returns an immutable list containing the installed decoders.
    • getDecoder

      static Optional<BodyAdapter.Decoder> getDecoder(TypeRef<?> objectType, @Nullable MediaType mediaType)
      Returns an Optional containing a Decoder that supports the given object type and media type. If mediaType is null, any decoder supporting the given object type is returned.