bodyAsJsonList<T, F> method
Decodes JSON body of the request as List
Example: final server = new Jaguar(); server.post('/api/book', (Context ctx) async { // Decode request body as JSON Map final List json = await ctx.req.bodyAsJsonList(); // ... }); await server.serve();
Implementation
Future<List<T>?> bodyAsJsonList<T, F>(
{conv.Encoding encoding = conv.utf8,
Converter<T, F>? convert,
Type? type}) async {
final String text = await bodyAsText(encoding);
final List? ret = conv.json.decode(text);
if (ret == null) {
return null;
}
if (convert != null) {
return ret.cast<F>().map(convert).toList();
}
/*{
final repo = _serializers[MimeTypes.json];
if (repo != null) {
final ser = repo.getByType<T>(type ?? T);
if (ser != null) {
return ser.fromList(ret.cast<Map>());
}
}
}*/
return ret.cast<T>();
}