bytes static method

List<int> bytes(
  1. Object? value
)

Turns value into UTF-8 bytes, in one pass.

No String is built in between. It follows the same rules as stringify. Use it for sockets, files, queues and HTTP client bodies.

Do not return it from a controller. Dox already turns a Map, a List or a model into JSON bytes for the response.

List<int> body = JSON.bytes({'name': 'dox'});
await File('data.json').writeAsBytes(body);

Implementation

static List<int> bytes(Object? value) {
  if (useSdkJsonEncoder) return _sdkBytes(value);
  return _jsonBytesEncoder.convert(value);
}