java.lang.Object
com.github.mizosoft.methanol.AdapterCodec
A group of
adapters
, typically targeting different mapping formats, that
facilitates creating HttpRequest.BodyPublisher
, HttpResponse.BodyHandler
and HttpResponse.BodySubscriber
implementations based on these adapters. The correct adapter is selected based on the object type
and a MediaType
specifying the desired format.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
A builder ofAdapterCodec
. -
Method Summary
Modifier and TypeMethodDescriptiondecoders()
Returns the list of decoders in this codec.<T> HttpResponse.BodyHandler
<Supplier<T>> deferredHandlerOf
(TypeRef<T> objectType) Returns aBodyHandler
that lazily decodes the response body into an object of the given type.<T> HttpResponse.BodySubscriber
<Supplier<T>> deferredSubscriberOf
(TypeRef<T> objectType, MediaType mediaType) Returns aBodySubscriber
that lazily decodes the response body into an object of the given type.encoders()
Returns the list of encoders in this codec.<T> HttpResponse.BodyHandler
<T> Returns aBodyHandler
that decodes the response body into an object of the given type.static AdapterCodec
static AdapterCodec.Builder
Returns a newAdapterCodec.Builder
.publisherOf
(Object object, MediaType mediaType) Returns aBodyPublisher
that encodes the given object into a request body.<T> HttpResponse.BodySubscriber
<T> subscriberOf
(TypeRef<T> objectType, MediaType mediaType) Returns aBodySubscriber
that decodes the response body into an object of the given type.
-
Method Details
-
encoders
Returns the list of encoders in this codec. -
decoders
Returns the list of decoders in this codec. -
publisherOf
Returns aBodyPublisher
that encodes the given object into a request body.- Throws:
UnsupportedOperationException
- if no encoder supporting the given object's runtime type or the given media type is found
-
subscriberOf
Returns aBodySubscriber
that decodes the response body into an object of the given type.- Throws:
UnsupportedOperationException
- if no decoder supporting the given object type or media type is found
-
deferredSubscriberOf
public <T> HttpResponse.BodySubscriber<Supplier<T>> deferredSubscriberOf(TypeRef<T> objectType, MediaType mediaType) Returns aBodySubscriber
that lazily decodes the response body into an object of the given type.- Throws:
UnsupportedOperationException
- if no decoder supporting the given object type or media type is found
-
handlerOf
Returns aBodyHandler
that decodes the response body into an object of the given type.- Throws:
UnsupportedOperationException
- if no decoder supporting the given object type is found
-
deferredHandlerOf
Returns aBodyHandler
that lazily decodes the response body into an object of the given type.- Throws:
UnsupportedOperationException
- if no decoder supporting the given object type is found
-
installed
-
newBuilder
Returns a newAdapterCodec.Builder
.
-