Module methanol

Interface BodyAdapter.Encoder

All Superinterfaces:
BodyAdapter
All Known Subinterfaces:
AbstractBodyAdapter.BaseEncoder
All Known Implementing Classes:
CharSequenceEncoder, ForwardingEncoder
Enclosing interface:
BodyAdapter

public static interface BodyAdapter.Encoder extends BodyAdapter
A BodyAdapter that encodes objects into request bodies.
  • Method Details

    • toBody

      HttpRequest.BodyPublisher toBody(Object value, @Nullable MediaType mediaType)
      Returns a HttpRequest.BodyPublisher that encodes the given object into a request body using the format specified by the given media type. If the given media type is null, the encoder uses its default format parameters (e.g., charset).
      Throws:
      UnsupportedOperationException - if the given object's runtime type or the given media type is not supported
    • toBody

      default <T> HttpRequest.BodyPublisher toBody(T value, TypeRef<T> typeRef, BodyAdapter.Hints hints)
      Returns a HttpRequest.BodyPublisher that encodes the given object into a request body based on the given TypeRef, using the given hints BodyAdapter.Hints for encoder-specific customization.
      Throws:
      UnsupportedOperationException - if any of the given type or hints' media type is not supported
      IllegalArgumentException - if the given object is not an instance of the given type
    • installed

      static List<BodyAdapter.Encoder> installed()
      Returns an immutable list containing the installed encoders.
    • getEncoder

      static 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 is null, 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 using MediaType's charset or UTF-8 if absent)
      • InputStream
      • byte[]
      • ByteBuffer
      • Path (represents a file from which the request content is sent)
      • Supplier<? extends InputStream>
      • Iterable<byte[]>