[dart-dio] Fixes errors when primitive return types are attempted to … (#7411)

* [dart-dio] Fixes errors when primitive return types are attempted to be deserialized as json

* Updates samples

* Removes old files
This commit is contained in:
Josh Burton
2020-12-09 16:07:29 +13:00
committed by GitHub
parent 61777b4a7c
commit 7fb5e2538b
8 changed files with 14 additions and 18 deletions

View File

@@ -94,6 +94,10 @@ class {{classname}} {
onReceiveProgress: onReceiveProgress,
){{#returnType}}.then((response) {
{{#returnTypeIsPrimitive}}
var data = response.data as {{{returnType}}};
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
{{#isResponseFile}}
final data = response.data;
{{/isResponseFile}}
@@ -113,6 +117,7 @@ class {{classname}} {
final data = _serializers.deserializeWith<{{{returnType}}}>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
{{/isArray}}
{{/isResponseFile}}
{{/returnTypeIsPrimitive}}
return Response<{{{returnType}}}>(
data: data,

View File

@@ -83,8 +83,7 @@ class StoreApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(Map);
final data = _serializers.deserializeWith<Map<String, int>>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as Map<String, int>;
return Response<Map<String, int>>(
data: data,

View File

@@ -250,8 +250,7 @@ class UserApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(String);
final data = _serializers.deserializeWith<String>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as String;
return Response<String>(
data: data,

View File

@@ -83,8 +83,7 @@ class StoreApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(Map);
final data = _serializers.deserializeWith<Map<String, int>>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as Map<String, int>;
return Response<Map<String, int>>(
data: data,

View File

@@ -250,8 +250,7 @@ class UserApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(String);
final data = _serializers.deserializeWith<String>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as String;
return Response<String>(
data: data,

View File

@@ -147,8 +147,7 @@ class FakeApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(bool);
final data = _serializers.deserializeWith<bool>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as bool;
return Response<bool>(
data: data,
@@ -251,8 +250,7 @@ class FakeApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(num);
final data = _serializers.deserializeWith<num>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as num;
return Response<num>(
data: data,
@@ -303,8 +301,7 @@ class FakeApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(String);
final data = _serializers.deserializeWith<String>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as String;
return Response<String>(
data: data,

View File

@@ -83,8 +83,7 @@ class StoreApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(Map);
final data = _serializers.deserializeWith<Map<String, int>>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as Map<String, int>;
return Response<Map<String, int>>(
data: data,

View File

@@ -250,8 +250,7 @@ class UserApi {
onReceiveProgress: onReceiveProgress,
).then((response) {
final serializer = _serializers.serializerForType(String);
final data = _serializers.deserializeWith<String>(serializer, response.data is String ? jsonDecode(response.data) : response.data);
var data = response.data as String;
return Response<String>(
data: data,