Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复列表数据类型出错 #687

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -629,23 +629,23 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
switch (clientAnnotation.parser) {
case retrofit.Parser.MapSerializable:
mapperCode = refer(
'(dynamic i) => ${_displayString(innerReturnType)}.fromMap(i as Map<String,dynamic>)',
'(dynamic i) => ${_displayString(innerReturnType)}.fromMap(i)',
);
break;
case retrofit.Parser.JsonSerializable:
if (innerReturnType?.isNullable ?? false) {
mapperCode = refer(
'(dynamic i) => i == null ? null : ${_displayString(innerReturnType)}.fromJson(i as Map<String,dynamic>)',
'(dynamic i) => i == null ? null : ${_displayString(innerReturnType)}.fromJson(i)',
);
} else {
mapperCode = refer(
'(dynamic i) => ${_displayString(innerReturnType)}.fromJson(i as Map<String,dynamic>)',
'(dynamic i) => ${_displayString(innerReturnType)}.fromJson(i)',
);
}
break;
case retrofit.Parser.DartJsonMapper:
mapperCode = refer(
'(dynamic i) => JsonMapper.fromMap<${_displayString(innerReturnType)}>(i as Map<String,dynamic>)!',
'(dynamic i) => JsonMapper.fromMap<${_displayString(innerReturnType)}>(i)',
);
break;
case retrofit.Parser.FlutterCompute:
Expand All @@ -660,6 +660,8 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
name: 'map',
)
.call([mapperCode])
.property('cast<${_displayString(innerReturnType)}>')
.call([])
.property('toList')
.call([]),
)
Expand Down Expand Up @@ -694,7 +696,7 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
(k, dynamic v) =>
MapEntry(
k, (v as List)
.map((i) => ${_displayString(type)}.fromMap(i as Map<String,dynamic>))
.map((i) => ${_displayString(type)}.fromMap(i))
.toList()
)
''');
Expand All @@ -704,7 +706,7 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
(k, dynamic v) =>
MapEntry(
k, (v as List)
.map((i) => ${_displayString(type)}.fromJson(i as Map<String,dynamic>))
.map((i) => ${_displayString(type)}.fromJson(i))
.toList()
)
''');
Expand All @@ -714,7 +716,7 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
(k, dynamic v) =>
MapEntry(
k, (v as List)
.map((i) => JsonMapper.fromMap<${_displayString(type)}>(i as Map<String,dynamic>)!)
.map((i) => JsonMapper.fromMap<${_displayString(type)}>(i))
.toList()
)
''');
Expand Down Expand Up @@ -766,18 +768,18 @@ You should create a new class to encapsulate the response.
switch (clientAnnotation.parser) {
case retrofit.Parser.MapSerializable:
mapperCode = refer(
'(k, dynamic v) => MapEntry(k, ${_displayString(secondType)}.fromMap(v as Map<String, dynamic>))',
'(k, dynamic v) => MapEntry(k, ${_displayString(secondType)}.fromMap(v))',
);
break;
case retrofit.Parser.JsonSerializable:
mapperCode = refer(
'(k, dynamic v) => MapEntry(k, ${_displayString(secondType)}.fromJson(v as Map<String, dynamic>))',
'(k, dynamic v) => MapEntry(k, ${_displayString(secondType)}.fromJson(v))',
);

break;
case retrofit.Parser.DartJsonMapper:
mapperCode = refer(
'(k, dynamic v) => MapEntry(k, JsonMapper.fromMap<${_displayString(secondType)}>(v as Map<String, dynamic>)!)',
'(k, dynamic v) => MapEntry(k, JsonMapper.fromMap<${_displayString(secondType)}>(v))',
);
break;
case retrofit.Parser.FlutterCompute:
Expand All @@ -788,7 +790,7 @@ You should create a new class to encapsulate the response.
future = true;
mapperCode = refer('''
(e) async => MapEntry(
e.key, await compute(deserialize${_displayString(secondType)}, e.value as Map<String, dynamic>))
e.key, await compute(deserialize${_displayString(secondType)}, e.value))
''');
break;
}
Expand Down Expand Up @@ -937,7 +939,7 @@ You should create a new class to encapsulate the response.
break;
case retrofit.Parser.DartJsonMapper:
mapperCode = refer(
'JsonMapper.fromMap<${_displayString(returnType)}>($_resultVar.data!)!',
'JsonMapper.fromMap<${_displayString(returnType)}>($_resultVar.data!)',
);
break;
case retrofit.Parser.FlutterCompute:
Expand Down Expand Up @@ -1089,10 +1091,10 @@ You should create a new class to encapsulate the response.
} else {
if (isGenericArgumentFactories(arg)) {
mappedVal +=
'(json)=>${_displayString(arg)}.fromJson(json as Map<String, dynamic>,${_getInnerJsonSerializableMapperFn(arg)}),';
'(json)=>${_displayString(arg)}.fromJson(json,${_getInnerJsonSerializableMapperFn(arg)}),';
} else {
mappedVal +=
'(json)=>${_displayString(arg)}.fromJson(json as Map<String, dynamic>),';
'(json)=>${_displayString(arg)}.fromJson(json),';
}
}
} else {
Expand All @@ -1106,9 +1108,9 @@ You should create a new class to encapsulate the response.
return '(json)=>json as ${_displayString(dartType, withNullability: dartType.isNullable)},';
} else {
if (dartType.isNullable) {
return '(json)=> json == null ? null : ${_displayString(dartType)}.fromJson(json as Map<String, dynamic>),';
return '(json)=> json == null ? null : ${_displayString(dartType)}.fromJson(json),';
} else {
return '(json)=>${_displayString(dartType)}.fromJson(json as Map<String, dynamic>),';
return '(json)=>${_displayString(dartType)}.fromJson(json),';
}
}
}
Expand Down
Loading