Module methanol

Interface BodyAdapter.Encoder

All Superinterfaces:
BodyAdapter
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 object, @Nullable MediaType mediaType)
      Returns a BodyPublisher that encodes the given object into a request body using the format specified by the given media type. If mediaType is null, the encoder's default format parameters (e.g. charset) are be used.
      Throws:
      UnsupportedOperationException - if the given object's runtime type or the given media type are not supported
    • installed

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

      static Optional<BodyAdapter.Encoder> getEncoder(TypeRef<?> objectType, @Nullable MediaType mediaType)
      Returns an Optional containing an Encoder that supports the given object type and media type. If mediaType is null, any encoder supporting the given object type is returned