jsonResponseProcessor function

void jsonResponseProcessor(
  1. Context context,
  2. dynamic result
)

ResponseProcessor to encode response value to json and also set mimetype to MimeType.json.

Implementation

void jsonResponseProcessor(Context context, dynamic result) {
  final info = context.route?.info;

  /* TODO
  final codec = context.codecFor(mimeType: MimeTypes.json);
  if (codec != null) {
    result = codec.to(result);
  }
   */

  context.response = StringResponse.cloneFrom(context.response,
      body: jsonEncode(result),
      statusCode: info?.statusCode,
      mimeType: info?.mimeType ?? MimeTypes.json,
      charset: info?.charset);
}