[Kotlin][Client] Added new option to enable moshi code generator#4781
[Kotlin][Client] Added new option to enable moshi code generator#4781wing328 merged 2 commits intoOpenAPITools:masterfrom
Conversation
|
Is there any disadvantage in this approach versus the old one? If not, I wouldn't mind that this would be the default behaviour without adding extras flags. |
|
@4brunu yep there is none. The new one improves the performance around converting json to objects + it does not use kotlin-reflects which reduces the project size by around 2-3mb. It should also simplify the usage of R8 (proguard). I would say that is significant. Quote from the moshi repository readme: "The JSON encoding of Kotlin types is the same whether using reflection or codegen. Prefer codegen for better performance and to avoid the kotlin-reflect dependency; prefer reflection to convert both private and protected properties." I would still recommend keeping both to not break existing code and provide a choice for people in which method to use. |
|
@Mordag thanks for the explanation, In this case, I think it's better to have a flag and let people choose which approach they prefer. |
|
Tested locally and the result is good. |
Moshi introduced a new code generator that provides a better performance than the current used KotlinJsonAdapterFactory solution. To enable the generator, every data class needs to use the new annotation
@JsonClass(generateAdapter = true).Changes made with this PR:
moshiCodeGen.PR checklist
./bin/(or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).master,4.3.x,5.0.x. Default:master.@jimschubert (2017/09) ❤️, @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11)