8000 🚀 Imply `List<Map>` as JSON content (#1737) · cfug/dio@4204004 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4204004

Browse files
authored
🚀 Imply List<Map> as JSON content (#1737)
Resolves #1736. ### New Pull Request Checklist - [x] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [x] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [x] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I'm adding - [x] I have updated the documentation (if necessary) - [x] I have run the tests without failures - [x] I have updated the `CHANGELOG.md` in the corresponding package
1 parent be2b0f5 commit 4204004

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

‎dio/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
*None.*
5+
- Imply `List<Map>` as JSON content in `ImplyContentTypeInterceptor`.
66

77
## 5.0.2
88

‎dio/lib/src/interceptors/imply_content_type.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class ImplyContentTypeInterceptor extends Interceptor {
3131
final String? contentType;
3232
if (data is FormData) {
3333
contentType = Headers.multipartFormDataContentType;
34-
} else if (data is Map || data is String) {
34+
} else if (data is List<Map> || data is Map || data is String) {
3535
contentType = Headers.jsonContentType;
3636
} else {
3737
// Do not log in the release mode.
3838
if (!_kReleaseMode) {
3939
dev.log(
40-
'${data.runtimeType} cannot be used'
40+
'${data.runtimeType} cannot be used '
4141
'to imply a default content-type, '
4242
'please set a proper content-type in the request.',
4343
level: 900,

‎dio/test/interceptor_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,18 @@ void main() {
376376
expect(response.requestOptions.contentType, 'application/json');
377377
});
378378

379+
test('sets application/json for List<Map> instances', () async {
380+
final dio = createDio();
381+
final response = await dio.get(
382+
'/echo',
383+
data: [
384+
{'hello': 'here'},
385+
{'hello': 'there'}
386+
],
387+
);
388+
expect(response.requestOptions.contentType, 'application/json');
389+
});
390+
379391
test('sets multipart/form-data for FormData instances', () async {
380392
final dio = createDio();
381393
final response = await dio.get(

0 commit comments

Comments
 (0)
0