Closed JasonHezz closed 4 years ago
目前还没有很好的插件机制来实现 这个需要修改generator的代码
https://github.com/trevorwang/retrofit.dart/blob/master/generator/lib/src/generator.dart 搜索 fromJ'son
欢迎PR
我的方案是在RestApi 增加String parser
parser 为JsonSerializable则是生成旧模式
parse为DartJsonMapper则生成JsonMapper.deserialize
默认值为JsonSerializable
不知道这个方案可行吗 如果可行 我会尝试在周末提交PR
OK. parser考虑使用枚举类型
On Apr 17, 2020, at 10:55 AM, JasonHezz notifications@github.com wrote:
我的方案是在RestApi 增加String parser
parser 为JsonSerializable则是生成旧模式
parse为DartJsonMapper则生成JsonMapper.deserialize
默认值为JsonSerializable
不知道这个方案可行吗 如果可行 我会尝试在周末提交PRc
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/trevorwang/retrofit.dart/issues/172#issuecomment-615009947, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5Y3V6RVSDMV2GLJH47ULRM7AKTANCNFSM4MJDZKBQ.
Can someone explain me what this ticket exactly does? Or is there documentation available
@vanlooverenkoen I'm sorry for that .
This is a discussion about how to custom deserialize json. I use dart json mapper and I prefer generate code
final value = JsonMapper.deserialize<T>(_result.data);
rather than
final value = T.fromJson(_result.data) ;
That's the PR address. If you want to use dart json mapper too. Try code blow
@RestApi(
baseUrl: 'http://xx/',
parser: Parser.DartJsonMapper,
)
abstract class RestClient {
}
But remember this only support deserialize , and @Body
is not working because I have few time now. Hopefully I can finish that in next weeks.
我使用dart-json-mapper做json解析 避免重复代码 在生成代码中我想替换如下代码
成
应该如何处理比较好