Class AbstractBodyAdapter
java.lang.Object
com.github.mizosoft.methanol.adapter.AbstractBodyAdapter
- All Implemented Interfaces:
BodyAdapter
- Direct Known Subclasses:
BasicAdapter
An abstract
BodyAdapter that implements BodyAdapter.isCompatibleWith(MediaType)
by allowing subclasses to specify a set of MediaTypes the adapter is compatible
with.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis interface abstracts the more-capableAbstractBodyAdapter.BaseDecoder.toObject(TypeRef, Hints)method and adds a default implementation forAbstractBodyAdapter.BaseDecoder.toObject(TypeRef, MediaType)that forwards to the former.static interfaceThis interface abstracts the more-capableAbstractBodyAdapter.BaseEncoder.toBody(Object, TypeRef, Hints)method and adds a default implementation forAbstractBodyAdapter.BaseEncoder.toBody(Object, MediaType)that forwards to the former.Nested classes/interfaces inherited from interface BodyAdapter
BodyAdapter.Decoder, BodyAdapter.Encoder, BodyAdapter.Hints -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractBodyAdapter(MediaType... compatibleMediaTypes) Creates anAbstractBodyAdaptercompatible with the given media types. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequest.BodyPublisherattachMediaType(HttpRequest.BodyPublisher publisher, @Nullable MediaType mediaType) Converts the given publisher into aMimeBodyPublisherthat has the given media type only if it is notnullorhas a wildcard, otherwise the given publisher is returned as-is.static CharsetcharsetOrDefault(@Nullable MediaType mediaType, Charset defaultCharset) Returns either the result ofMediaType.charsetOrDefault(Charset), or the given charset if the given media type isnull.static CharsetcharsetOrUtf8(@Nullable MediaType mediaType) Returns either the result ofMediaType.charsetOrDefault(Charset), orUTF-8if the given media type isnull.Returns an immutable set containing the media types this adapter is compatible with.final booleanisCompatibleWith(MediaType mediaType) Returnstrueif the format this adapter uses iscompatiblewith the given media type.protected voidrequireCompatibleOrNull(@Nullable MediaType mediaType) Requires that either this adapter iscompatiblewith the given media type, or the given media type isnull.protected voidrequireSupport(TypeRef<?> typeRef) Requires that this adaptersupportsthe given type.protected voidrequireSupport(TypeRef<?> typeRef, BodyAdapter.Hints hints) Requires that this adaptersupportsthe given type andis compatible withthe given hints' media type, if any.protected voidrequireSupport(Class<?> type) Requires that this adaptersupportsthe given type.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BodyAdapter
supportsType
-
Constructor Details
-
AbstractBodyAdapter
Creates anAbstractBodyAdaptercompatible with the given media types.
-
-
Method Details
-
isCompatibleWith
Description copied from interface:BodyAdapterReturnstrueif the format this adapter uses iscompatiblewith the given media type.- Specified by:
isCompatibleWithin interfaceBodyAdapter
-
compatibleMediaTypes
-
requireSupport
Requires that this adaptersupportsthe given type.- Throws:
UnsupportedOperationException- if this adapter doesn't support the given type.
-
requireSupport
Requires that this adaptersupportsthe given type.- Throws:
UnsupportedOperationException- if this adapter doesn't support the given type.
-
requireSupport
Requires that this adaptersupportsthe given type andis compatible withthe given hints' media type, if any.- Throws:
UnsupportedOperationException- if this adapter doesn't support the given type or is not compatible with the given hints' media type.
-
requireCompatibleOrNull
Requires that either this adapter iscompatiblewith the given media type, or the given media type isnull.- Throws:
UnsupportedOperationException- if this adapter is not compatible with the given media type.
-
charsetOrDefault
Returns either the result ofMediaType.charsetOrDefault(Charset), or the given charset if the given media type isnull. -
charsetOrUtf8
Returns either the result ofMediaType.charsetOrDefault(Charset), orUTF-8if the given media type isnull. -
attachMediaType
public static HttpRequest.BodyPublisher attachMediaType(HttpRequest.BodyPublisher publisher, @Nullable MediaType mediaType) Converts the given publisher into aMimeBodyPublisherthat has the given media type only if it is notnullorhas a wildcard, otherwise the given publisher is returned as-is.
-