Class MarshaledResponse
java.lang.Object
com.soklet.core.MarshaledResponse
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"].
Full documentation is available at https://www.soklet.com/docs/response-writing.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder used to construct instances ofMarshaledResponseviawithStatusCode(Integer).static classBuilder used to copy instances ofMarshaledResponseviacopy(). -
Method Summary
Modifier and TypeMethodDescriptioncopy()Vends a mutable copier seeded with this instance's data, suitable for building new instances.Optional<byte[]> getBody()The HTTP response body to write, if available.The HTTP cookies to write for this response.The HTTP headers to write for this response.The HTTP status code for this response.toString()static MarshaledResponse.BuilderwithStatusCode(Integer statusCode) Acquires a builder forMarshaledResponseinstances.
-
Method Details
-
withStatusCode
Acquires a builder forMarshaledResponseinstances.- Parameters:
statusCode- the HTTP status code for this response- Returns:
- the builder
-
copy
Vends a mutable copier seeded with this instance's data, suitable for building new instances.- Returns:
- a copier for this instance
-
toString
-
getStatusCode
The HTTP status code for this response.- Returns:
- the status code
-
getHeaders
-
getCookies
The HTTP cookies to write for this response.- Returns:
- the cookies to write
-
getBody
The HTTP response body to write, if available.- Returns:
- the response body to write, or
Optional.empty()) if no body should be written
-