Class MarshaledResponse

java.lang.Object
com.soklet.MarshaledResponse

@ThreadSafe public final class MarshaledResponse extends Object
A finalized representation of a Response, suitable for sending to clients over the wire.

Your application's ResponseMarshaler is responsible for taking the Response returned by a Resource Method as input and converting its Response.getBody() to a byte[].

For example, if a Response were to specify a body of List.of("one", "two"), a ResponseMarshaler might convert it to the JSON string ["one", "two"] and provide as output a corresponding MarshaledResponse with a body of UTF-8 bytes that represent ["one", "two"].

Alternatively, your Resource Method might want to directly serve bytes to clients (e.g. an image or PDF) and skip the ResponseMarshaler entirely. To accomplish this, just have your Resource Method return a MarshaledResponse instance: this tells Soklet "I already know exactly what bytes I want to send; don't go through the normal marshaling process".

Instances can be acquired via the withResponse(Response) or withStatusCode(Integer) builder factory methods. Convenience instance factories are also available via fromResponse(Response) and fromStatusCode(Integer).

Full documentation is available at https://www.soklet.com/docs/response-writing.

Author:
Mark Allen