@@ -258,6 +258,14 @@ class $clientName {
258
258
return Future.value(response);
259
259
}
260
260
261
+ // ------------------------------------------
262
+ // METHOD: _jsonDecode
263
+ // ------------------------------------------
264
+
265
+ dynamic _jsonDecode(http.Response r) {
266
+ return json.decode(utf8.decode(r.bodyBytes));
267
+ }
268
+
261
269
// ------------------------------------------
262
270
// METHOD: _request
263
271
// ------------------------------------------
@@ -880,7 +888,7 @@ class $clientName {
880
888
object: (s) {
881
889
// Handle deserialization of single object
882
890
if (s.ref != null || returnType.startsWith ('Union' )) {
883
- decoder = "return $returnType .fromJson(json.decode(r.body ));" ;
891
+ decoder = "return $returnType .fromJson(_jsonDecode(r ));" ;
884
892
} else {
885
893
// Just return the whole response and allow user to handle
886
894
if (returnType == 'dynamic' ) {
@@ -893,7 +901,7 @@ class $clientName {
893
901
// Handle deserialization for array of objects
894
902
if (s.items.ref != null ) {
895
903
decoder = """
896
- final list = json.decode(r.body ) as List;
904
+ final list = _jsonDecode(r ) as List;
897
905
return list.map((e) => ${s .items .ref }.fromJson(e)).toList();
898
906
""" ;
899
907
}
@@ -902,7 +910,7 @@ class $clientName {
902
910
// Handle deserialization for map of objects
903
911
if (s.valueSchema? .ref != null ) {
904
912
decoder = """
905
- final map = json.decode(r.body ) as Map<String, dynamic>;
913
+ final map = _jsonDecode(r ) as Map<String, dynamic>;
906
914
return map.map((k, v) => MapEntry(k, ${s .valueSchema ?.ref }.fromJson(v)));
907
915
""" ;
908
916
}
@@ -915,9 +923,9 @@ class $clientName {
915
923
} else if (returnType == 'Uint8List' ) {
916
924
decoder = "return r.bodyBytes;" ;
917
925
} else if (returnType.contains ('List' ) || returnType.contains ('Map' )) {
918
- decoder = "return $returnType .from(json.decode(r.body ));" ;
926
+ decoder = "return $returnType .from(_jsonDecode(r ));" ;
919
927
} else {
920
- decoder = "return json.decode(r.body );" ;
928
+ decoder = "return _jsonDecode(r );" ;
921
929
}
922
930
}
923
931
}
0 commit comments