body property

dynamic get body

An object representing the body of the Response, which will be encoded when used to Request.respond.

This is typically a map or list of maps that will be encoded to JSON. If the body was previously set with a Serializable object or a list of Serializable objects, this property will be the already serialized (but not encoded) body.

Implementation

dynamic get body => _body;
set body (dynamic initialResponseBody)

Sets the unencoded response body.

This may be any value that can be encoded into an HTTP response body. If this value is a Serializable or a List of Serializable, each instance of Serializable will transformed via its Serializable.asMap method before being set.

Implementation

set body(dynamic initialResponseBody) {
  dynamic serializedBody;
  if (initialResponseBody is Serializable) {
    serializedBody = initialResponseBody.asMap();
  } else if (initialResponseBody is List<Serializable>) {
    serializedBody =
        initialResponseBody.map((value) => value.asMap()).toList();
  }

  _body = serializedBody ?? initialResponseBody;
}