Module methanol

Interface BodyAdapter.Decoder

    • Method Detail

      • toObject

        <T> java.net.http.HttpResponse.BodySubscriber<T> toObject​(TypeRef<T> typeRef,
                                                                  @Nullable MediaType mediaType)
        Returns a HttpResponse.BodySubscriber that decodes the response body into an object of the given type using the format specified by the given media type. If the given media type is null, the decoder's default format parameters (e.g., charset) are used.
        Throws:
        java.lang.UnsupportedOperationException - if any of the given type or media type is not supported
      • toObject

        default <T> java.net.http.HttpResponse.BodySubscriber<T> toObject​(TypeRef<T> typeRef,
                                                                          BodyAdapter.Hints hints)
        Returns a HttpResponse.BodySubscriber that decodes the response body into an object of the given type using the given BodyAdapter.Hints.
        Throws:
        java.lang.UnsupportedOperationException - if any of the given type or hint's media type is not supported
      • toDeferredObject

        default <T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>> toDeferredObject​(TypeRef<T> typeRef,
                                                                                                               @Nullable MediaType mediaType)
        Returns a completed HttpResponse.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 uses its default format parameters (e.g., charset).
        Throws:
        java.lang.UnsupportedOperationException - if any of the given type or media type is not supported
      • toDeferredObject

        default <T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>> toDeferredObject​(TypeRef<T> typeRef,
                                                                                                               BodyAdapter.Hints hints)
        Returns a completed HttpResponse.BodySubscriber that lazily decodes the response body into an object of the given type using the given BodyAdapter.Hints.
        Throws:
        java.lang.UnsupportedOperationException - if any of the given type or media type is not supported
      • installed

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

        static java.util.Optional<BodyAdapter.Decoder> getDecoder​(TypeRef<?> typeRef,
                                                                  @Nullable MediaType mediaType)
        Returns a registered decoder that supports the given object type and media type, if any. If the given media type is null, any decoder supporting the given object type is returned.
      • basic

        static BodyAdapter.Decoder basic()
        Returns the basic decoder. The basic decoder is compatible with any media type, and supports decoding:
        • String (decoded using MediaType's charset or UTF-8 if absent)
        • InputStream
        • Reader (decoded using MediaType's charset or UTF-8 if absent)
        • byte[]
        • ByteBuffer
        • Stream<String> (response body lines; MediaType's charset or UTF-8 if absent)
        • ResponsePayload (here the decoder expects to receive the HttpResponse.ResponseInfo hint, and an AdapterCodec hint that will be used to convert the payload into the desired type; this is done automatically when sending the request through Methanol)
        • Publisher<List<ByteBuffer>> (a replaying publisher for the response body)
        • Void (discards the response body)