Interface BodyConverter<T>

Type Parameters:
T - The type this converter handles.

public interface BodyConverter<T>
Converts a Java object passed to RestRequest.body(Object) into a TransportBody.

A list of converters is consulted in order; the first converter whose canConvert(Object) returns true wins. The default converter list (applied automatically by RestClient) handles the common cases:

  1. HttpBody — passed through directly (streaming preferred over buffering)
  2. InputStream — wrapped in a streaming body
  3. byte[] — wrapped in a byte-array body
  4. File — wrapped in a file body

Custom converters are registered on the builder and are prepended to the default list (checked before the defaults). Use the of(Class, ThrowingConverter) factory for concise lambdas:

Example:

RestClient client = RestClient.builder() .bodyConverter(BodyConverter.of(MyBean.class, bean -> TransportBody.of(StringBody.of(mySerializer.write(bean))))) .build();

See Also:
Since:
9.2.1