Class AdapterCodec
java.lang.Object
com.github.mizosoft.methanol.AdapterCodec
A group of
adapters (encoders & decoders), typically targeting different mapping schemes, that facilitates creating
corresponding HttpRequest.BodyPublisher, HttpResponse.BodyHandler and HttpResponse.BodySubscriber
implementations. The correct adapter is selected based on the object type and caller's BodyAdapter.Hints, typically containing the MediaType of the desired mapping format.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder ofAdapterCodecinstances. -
Method Summary
Modifier and TypeMethodDescriptiondecoders()Returns the list of decoders in this codec.<T> HttpResponse.BodyHandler<Supplier<T>> deferredHandlerOf(TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aBodyHandlerthat lazily decodes the response body into an object of the given type.<T> HttpResponse.BodySubscriber<Supplier<T>> deferredSubscriberOf(TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aHttpResponse.BodySubscriberthat 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> handlerOf(TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aHttpResponse.BodyHandlerthat decodes the response body into an object of the given type.static AdapterCodecstatic AdapterCodec.BuilderReturns a newAdapterCodec.Builder.publisherOf(T value, BodyAdapter.Hints hints) Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body.publisherOf(T value, TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body with respect to the givenTypeRef.<T> HttpResponse.BodySubscriber<T> subscriberOf(TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type.toString()
-
Method Details
-
encoders
Returns the list of encoders in this codec. -
decoders
Returns the list of decoders in this codec. -
publisherOf
Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body.- Throws:
UnsupportedOperationException- if no encoder that supports encoding the given object or is compatible with the given hints' media type (if any) is found
-
publisherOf
public <T> HttpRequest.BodyPublisher publisherOf(T value, TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body with respect to the givenTypeRef.- Throws:
UnsupportedOperationException- if no encoder that supports encoding the given object type or is compatible with the given hints' media type (if any) is foundIllegalArgumentException- if the given object is not an instance of the givenTypeRef's raw type
-
subscriberOf
Returns aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type.- Throws:
UnsupportedOperationException- if no decoder that supports decoding to the given type or is compatible with the given hints' media type (if any) is found
-
deferredSubscriberOf
public <T> HttpResponse.BodySubscriber<Supplier<T>> deferredSubscriberOf(TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aHttpResponse.BodySubscriberthat lazily decodes the response body into an object of the given type.- Throws:
UnsupportedOperationException- if no decoder that supports decoding to the given type or is compatible with the given hints' media type (if any) is found
-
handlerOf
Returns aHttpResponse.BodyHandlerthat decodes the response body into an object of the given type. The decoder is selected based on the response body's media type as specified by theContent-Typeheader. If no such header exists, any decoder that supports decoding to the given type is selected.- Throws:
UnsupportedOperationException- if no decoder that supports decoding to the given type is found
-
deferredHandlerOf
public <T> HttpResponse.BodyHandler<Supplier<T>> deferredHandlerOf(TypeRef<T> typeRef, BodyAdapter.Hints hints) Returns aBodyHandlerthat lazily decodes the response body into an object of the given type. The decoder is selected based on the response body's media type as specified by theContent-Typeheader. If no such header exists, any decoder that supports decoding to the given type is selected.- Throws:
UnsupportedOperationException- if no decoder that supports decoding to the given type is found
-
toString
-
installed
-
newBuilder
Returns a newAdapterCodec.Builder.
-