- java.lang.Object
-
- com.github.mizosoft.methanol.AdapterCodec
-
public final class AdapterCodec extends java.lang.ObjectA group ofadapters(encoders&decoders), typically targeting different mapping schemes, that facilitates creating correspondingHttpRequest.BodyPublisher,HttpResponse.BodyHandlerandHttpResponse.BodySubscriberimplementations. The correct adapter is selected based on the object type and caller'sBodyAdapter.Hints, typically containing theMediaTypeof the desired mapping format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAdapterCodec.BuilderA builder ofAdapterCodecinstances.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<BodyAdapter.Decoder>decoders()Returns the list of decoders in this codec.<T> java.net.http.HttpResponse.BodyHandler<java.util.function.Supplier<T>>deferredHandlerOf(TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns aBodyHandlerthat lazily decodes the response body into an object of the given type.<T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>>deferredSubscriberOf(TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns aHttpResponse.BodySubscriberthat lazily decodes the response body into an object of the given type.java.util.List<BodyAdapter.Encoder>encoders()Returns the list of encoders in this codec.<T> java.net.http.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 AdapterCodecinstalled()static AdapterCodec.BuildernewBuilder()Returns a newAdapterCodec.Builder.<T> java.net.http.HttpRequest.BodyPublisherpublisherOf(T value, BodyAdapter.Hints hints)Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body.<T> java.net.http.HttpRequest.BodyPublisherpublisherOf(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> java.net.http.HttpResponse.BodySubscriber<T>subscriberOf(TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type.java.lang.StringtoString()
-
-
-
Method Detail
-
encoders
public java.util.List<BodyAdapter.Encoder> encoders()
Returns the list of encoders in this codec.
-
decoders
public java.util.List<BodyAdapter.Decoder> decoders()
Returns the list of decoders in this codec.
-
publisherOf
public <T> java.net.http.HttpRequest.BodyPublisher publisherOf(T value, BodyAdapter.Hints hints)Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body.- Throws:
java.lang.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> java.net.http.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:
java.lang.UnsupportedOperationException- if no encoder that supports encoding the given object type or is compatible with the given hints' media type (if any) is foundjava.lang.IllegalArgumentException- if the given object is not an instance of the givenTypeRef's raw type
-
subscriberOf
public <T> java.net.http.HttpResponse.BodySubscriber<T> subscriberOf(TypeRef<T> typeRef, BodyAdapter.Hints hints)
Returns aHttpResponse.BodySubscriberthat decodes the response body into an object of the given type.- Throws:
java.lang.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> java.net.http.HttpResponse.BodySubscriber<java.util.function.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:
java.lang.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
public <T> java.net.http.HttpResponse.BodyHandler<T> handlerOf(TypeRef<T> typeRef, BodyAdapter.Hints hints)
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:
java.lang.UnsupportedOperationException- if no decoder that supports decoding to the given type is found
-
deferredHandlerOf
public <T> java.net.http.HttpResponse.BodyHandler<java.util.function.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:
java.lang.UnsupportedOperationException- if no decoder that supports decoding to the given type is found
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
installed
public static AdapterCodec installed()
-
newBuilder
public static AdapterCodec.Builder newBuilder()
Returns a newAdapterCodec.Builder.
-
-