-
- All Superinterfaces:
BodyAdapter
- All Known Subinterfaces:
AbstractBodyAdapter.BaseDecoder
- All Known Implementing Classes:
ForwardingDecoder
- Enclosing interface:
- BodyAdapter
public static interface BodyAdapter.Decoder extends BodyAdapter
ABodyAdapterthat decodes response bodies into objects.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.github.mizosoft.methanol.BodyAdapter
BodyAdapter.Decoder, BodyAdapter.Encoder, BodyAdapter.Hints
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static BodyAdapter.Decoderbasic()Returns the basic decoder.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.static java.util.List<BodyAdapter.Decoder>installed()Returns an immutable list containing the installed decoders.default <T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>>toDeferredObject(TypeRef<T> typeRef, @Nullable MediaType mediaType)Returns a completedHttpResponse.BodySubscriberthat lazily decodes the response body into an object of the given type using the format specified by the given media type.default <T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>>toDeferredObject(TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns a completedHttpResponse.BodySubscriberthat lazily decodes the response body into an object of the given type using the givenBodyAdapter.Hints.<T> java.net.http.HttpResponse.BodySubscriber<T>toObject(TypeRef<T> typeRef, @Nullable MediaType mediaType)Returns aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type using the format specified by the given media type.default <T> java.net.http.HttpResponse.BodySubscriber<T>toObject(TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type using the givenBodyAdapter.Hints.-
Methods inherited from interface com.github.mizosoft.methanol.BodyAdapter
isCompatibleWith, supportsType
-
-
-
-
Method Detail
-
toObject
<T> java.net.http.HttpResponse.BodySubscriber<T> toObject(TypeRef<T> typeRef, @Nullable MediaType mediaType)
Returns aHttpResponse.BodySubscriberthat 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 isnull, 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 aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type using the givenBodyAdapter.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 completedHttpResponse.BodySubscriberthat lazily decodes the response body into an object of the given type using the format specified by the given media type. IfmediaTypeisnull, 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 completedHttpResponse.BodySubscriberthat lazily decodes the response body into an object of the given type using the givenBodyAdapter.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 isnull, 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 usingMediaType's charset or UTF-8 if absent)InputStreamReader(decoded usingMediaType's charset or UTF-8 if absent)byte[]ByteBufferStream<String>(response body lines;MediaType's charset or UTF-8 if absent)ResponsePayload(here the decoder expects to receive theHttpResponse.ResponseInfohint, and anAdapterCodechint that will be used to convert the payload into the desired type; this is done automatically when sending the request throughMethanol)Publisher<List<ByteBuffer>>(a replaying publisher for the response body)Void(discards the response body)
-
-