-
- All Superinterfaces:
BodyAdapter
- All Known Subinterfaces:
AbstractBodyAdapter.BaseEncoder
- All Known Implementing Classes:
ForwardingEncoder
- Enclosing interface:
- BodyAdapter
public static interface BodyAdapter.Encoder extends BodyAdapter
ABodyAdapterthat encodes objects into request bodies.
-
-
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.Encoderbasic()Returns the basic encoder.static java.util.Optional<BodyAdapter.Encoder>getEncoder(TypeRef<?> typeRef, @Nullable MediaType mediaType)Returns a registered encoder that supports the given object type and media type, if any.static java.util.List<BodyAdapter.Encoder>installed()Returns an immutable list containing the installed encoders.java.net.http.HttpRequest.BodyPublishertoBody(java.lang.Object value, @Nullable MediaType mediaType)Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body using the format specified by the given media type.default <T> java.net.http.HttpRequest.BodyPublishertoBody(T value, TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body based on the givenTypeRef, using the given hintsBodyAdapter.Hintsfor encoder-specific customization.-
Methods inherited from interface com.github.mizosoft.methanol.BodyAdapter
isCompatibleWith, supportsType
-
-
-
-
Method Detail
-
toBody
java.net.http.HttpRequest.BodyPublisher toBody(java.lang.Object value, @Nullable MediaType mediaType)Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body using the format specified by the given media type. If the given media type isnull, the encoder uses its default format parameters (e.g., charset).- Throws:
java.lang.UnsupportedOperationException- if the given object's runtime type or the given media type is not supported
-
toBody
default <T> java.net.http.HttpRequest.BodyPublisher toBody(T value, TypeRef<T> typeRef, BodyAdapter.Hints hints)Returns aHttpRequest.BodyPublisherthat encodes the given object into a request body based on the givenTypeRef, using the given hintsBodyAdapter.Hintsfor encoder-specific customization.- Throws:
java.lang.UnsupportedOperationException- if any of the given type or hints' media type is not supportedjava.lang.IllegalArgumentException- if the given object is not an instance of the given type
-
installed
static java.util.List<BodyAdapter.Encoder> installed()
Returns an immutable list containing the installed encoders.
-
getEncoder
static java.util.Optional<BodyAdapter.Encoder> getEncoder(TypeRef<?> typeRef, @Nullable MediaType mediaType)
Returns a registered encoder that supports the given object type and media type, if any. If the given media type isnull, any encoder supporting the given object type is returned.
-
basic
static BodyAdapter.Encoder basic()
Returns the basic encoder. The basic encoder is compatible with any media type, and supports encoding any subtype of:CharSequence(encoded usingMediaType's charset or UTF-8 if absent)InputStreambyte[]ByteBufferPath(represents a file from which the request content is sent)Supplier<? extends InputStream>Iterable<byte[]>
-
-