-
Notifications
You must be signed in to change notification settings - Fork 177
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
The Moshi converter option doesn't support moshi-codegen #69
Comments
Apparently that's not an official solution, though. So... my bad. It seems one should either stick to |
field:
(@Json --> @field:Json)
@gobetti @tfcporciuncula Thanks for your feedback.Em. now you could use customize annotation option to solve your problem at first. (#19 ) |
@gobetti @tfcporciuncula As I tested.the result like this. It works with data class Model(
@field:Json(name = "total_pages") val totalPages: Int = 0
)
data class NoFieldModel(
@Json(name = "total_pages") val totalPages: Int = 0
) Is there anything I was missing? 😢 |
Hi @wuseal , yes, you are using KotlinJsonAdapterFactory when you set up moshi - as I mention at the beginning of this ticket, this could be avoidable by either using
Thanks! |
@gobetti Yes, when using Moshi with kotlin we also add data class Model(
@field:Json(name = "total_pages") val totalPages: Int = 0
) Or as the last method you mentioned, you could do this setting @JsonClass(generateAdapter = true)
data class Model(
@Json(name = "total_pages") val totalPages: Int = 0
) Hope it works for you 😄 |
Hi @wuseal! Yes, I mean there is nowadays a better solution than using It's okay that one can click "Others by customize" but when you already have an option "Moshi", IMHO selecting "Others" wouldn't be expected to be the correct choice. Thanks again! |
@gobetti Did you meaning making |
Hi @wuseal, based on the comments in the issue shared by @tfcporciuncula the solution using codegen is the best, and it is also the last chronological commit I had when fixing the deserialization issue (shared in the comments above) :D So adding the annotation for the class will be a final solution for this and should work for anyone using Moshi and Moshi codegen without requiring reflection 👍 |
Bottom line is: the current behavior is correct and this issue can be closed :) |
@gobetti Yes, use Thanks. |
@tfcporciuncula I'm not sure it should be closed because it is still a welcome change, but @wuseal I agree to postpone it until the documentation states that Another option is to let users of this plugin to choose between codegen and reflection. The reason why both options are still mentioned in the docs is this (quoting from there):
I'll update the title to reflect our discussion above. Thanks guys! |
Yeah, I was referring to the original issue (i.e. considering supporting
I personally don't think these are strong arguments to keep things as they are today. If you look from other perspective, you can say the codegen alternative is actually simpler since you don't need to add any custom adapter. And it might be the first option in the docs just because codegen is more recent - it was added only in the last release. Based on the docs, the only reason one should stick to reflection is if they have private and protected properties. Otherwise, codegen should be an obvious choice since we get more performance and less dependencies. |
@tfcporciuncula First of all, thank you for your answer.And then again, you said that this feature was recently added, so in order to maintain compatibility, in order to maintain and the previous functional finance, I think it would be better to use the current annotation.Because one of our goals is to enable users to achieve their goals more smoothly, so that most users can quickly and smoothly achieve their goals.If you change it to a new annotation, then the previous version of the library, it may not resolve the new annotation.This will lead to new problems, the compiler did not pass. |
@wuseal what about my previous comment:
|
@gobetti How to choose? Add another option? |
Yes, today we have a single option called Moshi which implies using reflection.
|
@gobetti Ok, Let's add |
…generate `JsonAdapter` class for the class annotated with this annotation #69
Hi @wuseal , I noticed this was released in 2.3.0, thank you! |
…generate `JsonAdapter` class for the class annotated with this annotation #69
Hi, this plugin is super awesome but I found this bug today where all of the annotated properties in my generated model failed to be deserialised. As of the way the classes are generated today, one needs to use the
KotlinJsonAdapterFactory
:i.e. adding a dependency to
kotlin-reflect
, a considerably heavy library. It would be nice to just do:.addConverterFactory(MoshiConverterFactory.create())
@tfcporciuncula pointed me to a simple solution which is using the more explicit annotation
@field:Json
instead of simply@Json
.EDIT:
however that is NOT a recommended solution! It would work with these Gradle dependencies:
By supporting the moshi codegen, the need of
KotlinJsonAdapterFactory
can be removed and the simple annotation@Json
can be kept, one just needs to annotate the class with@JsonClass(generateAdapter = true)
and update the dependencies to:The text was updated successfully, but these errors were encountered: