{8.2.0-new} POJO Marshalling

By default, JSON support is provided for HTTP request and response bodies. Other languages can be specified using any of the following builder methods:

- {@link oajr.client2.RestClientBuilder}
  - {@link oajr.client2.RestClientBuilder#json() json()}
  - {@link oajr.client2.RestClientBuilder#simpleJson() simpleJson()}
  - {@link oajr.client2.RestClientBuilder#xml() xml()}
  - {@link oajr.client2.RestClientBuilder#html() html()}
  - {@link oajr.client2.RestClientBuilder#plainText() plainText()}
  - {@link oajr.client2.RestClientBuilder#msgPack() msgPack()}
  - {@link oajr.client2.RestClientBuilder#uon() uon()}
  - {@link oajr.client2.RestClientBuilder#urlEnc() urlEnc()}
  - {@link oajr.client2.RestClientBuilder#openApi() openApi()}

##### Example:

// Create a basic REST client with Simplified-JSON support. // Typically easier to use when performing unit tests. RestClient client = RestClient.create().simpleJson().build();

Clients can also support multiple languages:

##### Example:

// Create a REST client with support for multiple languages. RestClient client1 = RestClient.create().json().xml().openApi().build(); // Create a REST client with support for all supported languages. RestClient client2 = RestClient.create().universal().build();

When using clients with multiple language support, the request language is selected by setting the Content-Type request header.

// Create a REST client with support for multiple languages. RestClient client = RestClient.create().universal().build(); client.post(URI, myBean) .contentType("application/json") .complete() .assertStatus().code().is(200);

Languages can also be specified per-request.

// Create a REST client with no default languages supported. RestClient client = RestClient.create().build(); // Use JSON for this request. client.post(URI, myBean) .json() .complete() .assertStatus().code().is(200);

The {@link oajr.client2.RestClientBuilder} class provides convenience methods for setting common serializer and parser settings.

##### Example:

// Create a basic REST client with JSON support. // Use single-quotes and whitespace. RestClient client1 = RestClient.create().json().sq().ws().build(); // Same, but using properties. RestClient client2 = RestClient .create() .json() .set(WSERIALIZER_quoteChar, '\'') .set(WSERIALIZER_useWhitespace, true) .build();

Other methods are also provided for specifying the serializers and parsers used for lower-level marshalling support:

- {@link oajr.client2.RestClientBuilder}
  - {@link oajr.client2.RestClientBuilder#serializer(Serializer) serializer(Serializer)}
  - {@link oajr.client2.RestClientBuilder#parser(Parser) parser(Parser)}
  - {@link oajr.client2.RestClientBuilder#marshall(Marshall) marshall(Marshall)}

HTTP parts (headers, query parameters, form data...) are serialized and parsed using the {@link oaj.httppart.HttpPartSerializer} and {@link oaj.httppart.HttpPartParser} APIs. By default, clients are configured to use {@link oaj.oapi.OpenApiSerializer} and {@link oaj.oapi.OpenApiParser}. These can be overridden using the following methods:

- {@link oajr.client2.RestClientBuilder}
  - {@link oajr.client2.RestClientBuilder#partSerializer(Class) partSerializer(Class<? extends HttpPartSerializer>)}
  - {@link oajr.client2.RestClientBuilder#partParser(Class) partParser(Class<? extends HttpPartParser>)}